使用 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)

但是,输出似乎是 html 和 CSS:

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

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

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