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

REST API Integration: certificate verify failed (_ssl.c:877)

Fitri
Giga Contributor

Hi, I tried do some integration towards serviceNow using python script and referring example given in this link to update the records: Table API Python

Here is my code:

#Need to install requests package for python
#sudo easy_install requests
import requests
 
# Set the request parameters
url = 'https://company.owndomain.com/api/now/table/sc_req_item/2a2851fe88709010b9120e9b506dd9a9'
user = 'username'
pwd = 'password'
 
# Set proper headers
headers = {"Content-Type":"application/json","Accept":"application/json"}
 
# Do the HTTP request
response = requests.patch(url, auth=(user, pwd), headers=headers ,data='{"u_switch_status_automation":"In Processing using Python", "u_switch_description":"The Automation currently processing this SR using Python"}')
 
# 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
print('Status:',response.status_code,'Headers:',response.headers,'Response:',response.json())

 

And the result I got is as follows:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 343, in _make_request
    self._validate_conn(conn)
  File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 839, in _validate_conn
    conn.connect()
  File "/usr/lib/python3.6/site-packages/urllib3/connection.py", line 344, in connect
    ssl_context=context)
  File "/usr/lib/python3.6/site-packages/urllib3/util/ssl_.py", line 347, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "/usr/lib64/python3.6/ssl.py", line 365, in wrap_socket
    _context=self, _session=session)
  File "/usr/lib64/python3.6/ssl.py", line 773, in __init__
    self.do_handshake()
  File "/usr/lib64/python3.6/ssl.py", line 1033, in do_handshake
    self._sslobj.do_handshake()
  File "/usr/lib64/python3.6/ssl.py", line 645, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:877)

Am I missing something or need to do some configuration for this? 

1 ACCEPTED SOLUTION

Hi,

I tried it and for me it work from one of my MID server using python.

Thanks,
Ashutosh

View solution in original post

11 REPLIES 11

Hi, thank you for the reply. 

After do some information searching, I found this link regarding the SSL and Cert:  Outbound web services mutual authentication. What I am trying to do currently, is it considered as outbound HTTPS connections as well?

Thanks,

Fitri Izuan 

Hi,

You are doing a call to servicenow right? If yes then you actually dont need this. It is mentioned as well.

For ServiceNOw it is Inbound traffic and not outbound.

Thanks,
Ashutosh

Hi, 

Yes, correct. I am doing a call to serviceNow, not from serviceNow to other 3rd party. 

Thank you for the clarification.

Regards,

Fitri Izuan.

Yeah.

If you got the answer then close the thread.


Thanks,
Ashutosh

Hi, 

I still haven't get the answer on what is the thing caused the error as what I am doing currently should be not an issue with the SSL because I am using inbound traffic as you have clarified.

Thanks, 

Fitri Izuan