Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

What causes SSLCertVerificationError, CERTIFICATE_VERIFY_FAIL when using Python on Windows?

Ask Question

If I do this:

import requests
url = 'https://us-street.api.smartystreets.com/i/redacted/the/url/because/its/an/api/call/with/private/info'
r = requests.get(url)

I get this:

SSLError: HTTPSConnectionPool(host='us-street.api.smartystreets.com', port=443): Max retries exceeded with url: /i/redacted/the/url/because/its/an/api/call/with/private/info (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1131)')))

However, when I put the URL directly into my Chrome browser, I get a response.

The key here is that the request works through the browser, so it's probably something limited to Python. Some sleuthing leads us to the following:

https://stackoverflow.com/a/65860355/5478086

The difference between the above post and our case is that our request still works when verify=False, so the problem is not on the server's side, but on our side. And so, we try the above answer

pip install python-certifi-win32

Or on Anaconda

conda install -c conda-forge python-certifi-win32

(h/t to iambr from this post.)

And now we can successfully make and verify requests from the above domain.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.