Import SSL certificate into Python, SSLError (CERTIFICATE_VERIFY_FAILED)

How can I import an SSL certificate into Python?

In my company I had the problem that I could not execute a Python script. I kept getting an error message when trying to access a server.

The error message was like that:

urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='', port=443): Max retries exceeded with url: /rpc (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate
verify failed: unable to get local issuer certificate (_ssl.c:1123)')))

The problem here is that the company uses its own SSL certificate, which Python does not recognise. This must first be made known to Python.

To do this, we open the “cacert.pem” file in the “certifi” directory. The path may differ depending on the installation location.

The certificate can be added at the end in plain text:

Leave a Reply

Your email address will not be published. Required fields are marked *