The CreatorCon Call for Content is officially open! Get started here.

REST API - Python - SSL Certificate Error - Why?

Ken83
Mega Guru

Can anyone provide some insight on this issue. When using Python to access the REST API in my test environment, i'm getting this error. 

HTTPSConnectionPool(host='my.servicenow.instance', port=443): Max retries exceeded with url: /api/now/table/incident?sysparm_limit=1(Caused by SSLError(FileNotFoundError(2, 'No such file or directory')))

I tried setting the verify flag to false and this is the error that I got...(using phantom)

(requests.get(url, auth=(user, pwd), headers=headers, verify=False): Status: 401 Headers: {'Set-Cookie': 'JSESSIONID=very-long-alphanumeric-key-here; Path=/; HttpOnly;Secure, BIGipServerpool_envname=478370058.41278.0000; path=/; Httponly; Secure', 'Content-Encoding': 'gzip', 'WWW-Authenticate': 'BASIC realm="Service-now"', 'Pragma': 'no-store,no-cache', 'Cache-control': 'no-cache,no-store,must-revalidate,max-age=-1', 'Expires': '0', 'Content-Type': 'application/json;charset=UTF-8', 'Transfer-Encoding': 'chunked', 'Date': 'Wed, 30 Jan 2019 19:23:26 GMT', 'Server': 'ServiceNow', 'Strict-Transport-Security': 'max-age=63072000; includeSubDomains', 'Connection': 'close'} Error Response: {'error': {'message': 'User Not Authenticated', 'detail': 'Required to provide Auth information'}, 'status': 'failure'}

I have checked several sources and I cannot find any information on handling SSL certificates with Python using the REST API but I also don't believe you typically deal with that with Python so I'm really confused on why I'd be getting this error. Any insight is greatly appreciated.

2 REPLIES 2

Jace Benson
Mega Sage

Does this fail with other Python methods/libraries?

import http.client

conn = http.client.HTTPSConnection("my.servicenow.instance")

payload = ""

headers = { 'Authorization': "..." }

conn.request("GET", "/api/now/table/incident?sysparm_limit=1", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))