Alex Hellier
Alex Hellier

Reputation: 485

Python SSL CERTIFICATE_VERIFY_FAILED

I'm using the following code to interact with a Magento webstore using the XMLRPC api. Magento API Python XMLRPC

Everything was working ok until we made a change on our web server to SSL

Now I'm getting the following error.

ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)

I'm not sure why the certificate is failing as we have an EV certificate and all browsers are showing this as ok.

My connection string is:

How can I resolve this / over-ride the code

I'm fairly new to Python so please go easy :o)

magento = MagentoAPI("www.website.co.uk", 443, "myUsername", "myPassword", "/api/xmlrpc", True)

Upvotes: 1

Views: 2652

Answers (2)

Vitaly
Vitaly

Reputation: 81

Python verifies certs via its own bundle, check where it is located by

>>> import certifi
>>> certifi.where()
'/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site- 
packages/certifi/cacert.pem'

and add your certificates to the end of that file.

Upvotes: 1

Klaus D.
Klaus D.

Reputation: 14369

Python, or better the OpenSSL library it is using, can not verify the validity of the certificate of the server. There are many possible reasons: bad configuration, missing intermediate or CA certificate, wrong CN...

A first step could be to go to this site and let it test the SSL/TLS capabilities of the server: https://www.ssllabs.com/ssltest/

It will give you hints on how to solve problems as well.

Upvotes: 2

Related Questions