'Why do HTTPS requests produce SSL CERTIFICATE_VERIFY_FAILED error?

Here is my Python code:

    import requests
    requests.get('https://google.com')

This is the error:

requests.exceptions.SSLError: HTTPSConnectionPool(host='google.com', port=443):
Max retries exceeded with url: / (Caused by SSLError(SSLError(1, 
'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)'),))

Using Insomnia gives me an error related with certificates:

Error shown in Insomnia

My OS is Windows 7 Professional.



Solution 1:[1]

requests.get('https://google.com', verify='/path/to/certfile')

or you can skip verifications by doing this:

requests.get('https://google.com', verify=False)

You should specify your CA.

Solution 2:[2]

This fixed it: Python referencing old SSL version

The openssl versions used to differ for python and the one offered by homebrew

if brew install python --with-brewd-openssl doesn't work try
brew install openssl brew install python
after uninstalling python

Solution 3:[3]

If you are running under business network, contact the network administrator to apply required configurations at the network level.

Solution 4:[4]

In the requests.get you can set the verify flag to False. This way the handshake between the program and the server is going to be ignored.

-- This isn't a guaranteed method because some servers have strict policy to deliver responses to requests.

Solution 5:[5]

You might add header and verify argument to by-pass ssl certificate security.

r = requests.get(URL, headers = {'User-agent': 'your bot 0.1'}, verify=False)

You should specify path your certificate if you have.

Solution 6:[6]

I resolved my problem by installing openssl you can go here and download the Light version or any version suited to your needs: https://slproweb.com/products/Win32OpenSSL.html

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2
Solution 3 Rola
Solution 4
Solution 5 HITESH GUPTA
Solution 6 helloWORLD