How to avoid ConnectionError ServiceNow REST API

bhain
Kilo Contributor

Hello! I'm trying to connect to the API using a basic Python script from the document, and login credentials that work in my web browser and having no luck.

Getting:  ConnectionError: HTTPSConnectionPool(host='mycompanydev.service-now.com', port=443): Max retries exceeded with url: /api/now/table/incident?sysparm_limit=10 (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fe64850f4a8>: Failed to establish a new connection: [Errno 110] Connection timed out',))

Wondering if anyone knows the source of this issue/ how to troubleshoot.

Using a basic table API script from the Servicenow Rest API explorer.

 

#Need to install requests package for python
#easy_install requests
import requests

# Set the request parameters
url = 'https://mycompanydev.service-now.com/api/now/table/incident?sysparm_limit=10'

# Eg. User name="admin", Password="admin" for this code sample.
user = 'myusername'
pwd = 'mypassword'

# Set proper headers
headers = {"Content-Type":"application/json","Accept":"application/json"}

# Do the HTTP request
response = requests.get(url, auth=(user, pwd), headers=headers , timeout=None)

# Check for HTTP codes other than 200
if response.status_code != 200: 
    print('Status:', response.status_code, 'Headers:', response.headers, 'Error Response:',response.json())
    exit()

# Decode the JSON response into a dictionary and use the data
data = response.json()
print(data)

 

EDIT: Works for me on desktop, but fails using the VPC hosted Juypter Lab I was running it in. It might have to do with the VPC server and company security. 

Really need the VPC hosted one to be able to use it effectively at company though, so I guess that's the issue,

When I set up PIP for desktop python, I put in some extra code to get through a "proxy", not sure what that means.

8 REPLIES 8

abhijitkhewale
Mega Expert

Could you please share your script it will be easier to suggest on that basis.

Posted the code as an edit.

I have tested your code and it is working for me with my development instance.

 

find_real_file.png 

Works for me on desktop, but fails using the VPC hosted Juypter Lab I was running it in. It might have to do with the VPC server and company security. 

 

Really need the VPC hosted one to be able to use it effectively at company though, so I guess that's the issue,