简体   繁体   English

使用 Python 从 ServiceNow 实例将数据导出为 CSV 文件

[英]Exporting data as CSV file from ServiceNow instance using Python

I have some data in an instance that I would like to export to a CSV file using Python and the REST API. I wish to use REST, because there are some rows missing when emailed as a.CSV file.我在一个实例中有一些数据,我想使用 Python 和 REST API 导出到 CSV 文件。我希望使用 REST,因为当作为 .CSV 文件通过电子邮件发送时,缺少一些行The query gives me 12,000 rows, however, the file that is emailed to me only contains 10,001 rows.查询给了我 12,000 行,但是,通过电子邮件发送给我的文件只包含 10,001 行。

Here is the data I wish to export to CSV:这是我希望导出到 CSV 的数据:

在此处输入图像描述

I have added a filter, and it is only about 12,000 rows that I wish to export.我添加了一个过滤器,但我希望导出的只有大约 12,000 行。 This is what I am doing in Python:这就是我在 Python 中所做的:

user = 'user'
pwd = 'password'





# Set the request parameters
url = 'https://instancename.service-now.com/nav_to.do?uri=%2Fx_snc_instance_dc_test_ci_test_system_list.do&sysparm_query=import_dateONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^nameSTARTSWITHfb^ORname?CSV'



# Eg. User name="username", Password="password" for this code sample.

requests.get('https://api.github.com/user', auth=('user', 'pwd'))




# Do the HTTP request
response = requests.get(url, auth=(user, pwd))


# Check for HTTP codes other than 200
if response.status_code != 200: 
    print('Status:', response.status_code, 'Headers:', response.headers, 'Error Response:', response.content)
    exit()
    
    
    
# Parse JSON response body 
print(response.content)

However, the output appears to be html and CSS:然而,output 似乎是 html 和 CSS:

在此处输入图像描述

I am still troubleshooting this, and would like to know if my above code is correct, or what needs to be tweaked to have the data exported in a.csv data-frame format and to a csv file.我仍在对此进行故障排除,并且想知道我的上述代码是否正确,或者需要进行哪些调整才能将数据导出为 .csv 数据帧格式并导出为 csv 文件。 Any suggestions are appreciated.任何建议表示赞赏。 Thank you谢谢

ServiceNow will limit exports to 10,000 records by default for performance reasons.出于性能原因,ServiceNow 默认将导出限制为 10,000 条记录。

Try adding &sysparm_limit=20000 to your URL.尝试将&sysparm_limit=20000添加到您的 URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM