0
votes

I am new to service now API access through python, below code I wrote but its failing with error. the same API URL if I access through internet explorer(https://myinstance.service-now.com/api/now/table/incident) I am getting some result. but through Python code its throwing error.

Can some one view my code and help me if any issues or share me the solution to read the service now API through python code.

import pysnow
# Configure authentication settings. Instance can be 'michmed', 'ummedtest', or 'ummeddev'
auth = {'instance': 'myinstance', 'username': 'username', 'password': 'XXXXXXX'}
# Connect to the ServiceNow instance
s = pysnow.Client(instance=auth['instance'], user=auth['username'], password=auth['password'])
# Fetch incident INC0012555, then print it.
r = s.query(table='incident', query={'number': 'INC0646025'})
print(r.get_one(fields=[]))

Error:

"C:\Program Files\Python37\python.exe" connectto_servicenow.py

Traceback (most recent call last):

File "C:\Program Files\Python37\lib\site-packages\urllib3\connection.py", line 159, in _new_conn

(self._dns_host, self.port), self.timeout, **extra_kw)

File "C:\Program Files\Python37\lib\site-packages\urllib3\util\connection.py", line 57, in create_connection

for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):

File "C:\Program Files\Python37\lib\socket.py", line 748, in getaddrinfo

for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno 11001] getaddrinfo failed

1

1 Answers

1
votes

I am able to find the issue.

1) In service now instance settings, your server IP(code hosted) should be white listed to access the API through code/program.

2) Service account or the ID used to execute the Python code should have internet access(could be behind firewall, get it fixed)

after addressing the above two points I am able to access the service now through Python.