簡體   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