简体   繁体   中英

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. I'm using Anaconda version 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 . I am using REST . Not sure if that will help.

You need to postfix download type after table name. For eg CSV in below example. Rest of the URL for report is same as you would download report manually from servicenow .

Here is a working code that downloads a report in CSV format. Report URL and ID will need to be changed as per your organization.

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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