繁体   English   中英

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

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

我在一个实例中有一些数据,我想使用 Python 和 REST API 导出到 CSV 文件。我希望使用 REST,因为当作为 .CSV 文件通过电子邮件发送时,缺少一些行查询给了我 12,000 行,但是,通过电子邮件发送给我的文件只包含 10,001 行。

这是我希望导出到 CSV 的数据:

在此处输入图像描述

我添加了一个过滤器,但我希望导出的只有大约 12,000 行。 这就是我在 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)

然而,output 似乎是 html 和 CSS:

在此处输入图像描述

我仍在对此进行故障排除,并且想知道我的上述代码是否正确,或者需要进行哪些调整才能将数据导出为 .csv 数据帧格式并导出为 csv 文件。 任何建议表示赞赏。 谢谢

出于性能原因,ServiceNow 默认将导出限制为 10,000 条记录。

尝试将&sysparm_limit=20000添加到您的 URL。

暂无
暂无

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

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