【发布时间】:2021-01-31 23:42:05
【问题描述】:
我在一个实例中有一些数据,我想使用 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 文件。任何建议表示赞赏。谢谢
【问题讨论】:
标签: python pandas servicenow servicenow-rest-api