简体   繁体   English

使用 Python 3.5.2 将 ServiceNow 数据下载到 CSV 文件中

[英]Downloading ServiceNow data into a CSV file using Python 3.5.2

Can someone please tell me how to use SOAP and WSDL functionality along with ServiceNow in order to download data into a CSV file.有人可以告诉我如何将 SOAP 和 WSDL 功能与 ServiceNow 一起使用,以便将数据下载到 CSV 文件中。 I'm using Anaconda version 3.5.2我正在使用 Anaconda 版本 3.5.2

A sample script would be really helpful一个示例脚本会非常有帮助

Downgrading is not an option for me.降级不是我的选择。

I also had a requirement at my work to download and process a service-now report.我的工作中还需要下载和处理服务即时报告。 You can do it either using SOAP , REST or WSDL .您可以使用SOAPRESTWSDL I am using REST .我正在使用REST Not sure if that will help.不确定这是否会有所帮助。

You need to postfix download type after table name.您需要在表名后postfix下载类型。 For eg CSV in below example.例如下面示例中的CSV Rest of the URL for report is same as you would download report manually from servicenow .报告 URL 的其余部分与您从servicenow手动下载报告相同。

Here is a working code that downloads a report in CSV format.这是一个下载CSV格式报告的工作代码。 Report URL and ID will need to be changed as per your organization.报告 URL 和 ID 将需要根据您的组织进行更改。

import requests
import getpass


url = "https://yourcompany.service-now.com/sys_report_template.do?CSV&jvar_report_id="1234567890abcdefg"

uname=raw_input("Enter Username: ")
pswd=getpass.getpass(prompt='Enter Password: ', stream=None)

r=requests.get(url, auth=(uname, pswd))



if r.status_code==requests.codes.ok:
    print("Requests made a connection.\n")
    f=open(r'C:\dump.csv', 'w')
    f.write(r.content)
    f.close()

else:
    print("\nAn error occured while establishing a connection.")
    print("Status code returned: ",r.status_code)

c=input("\nEnter a key to exit.\n")

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

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