Fixing Python Error – HTTPS requests produce SSL CERTIFICATE_VERIFY_FAILED error

Python Error – HTTPS requests produce SSL CERTIFICATE_VERIFY_FAILED error is an error which occurs when the handshake between the program and the server points to an SSL problem.

In this article I am going to show you why this error is happening and how you can solve this error. I am also going to share with you other possible solutions which have worked for many developers who suffered

Exploring the Python Error – HTTPS requests produce SSL CERTIFICATE_VERIFY_FAILED error

This is an error which occurs when the handshake between the program and the server points to an SSL problem.

The error message should look like the message bellow. Make sure you are not dealing with another error.

                                                                       #
HTTPSConnectionPool: Max retries exceeded with url: / (Caused by SSLError(SSLError(1,  
'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)'),))
                                                                       #

Bellow is a number of tested solutions that I have tried and have worked for me.

Solution 1 : use verify=False to ignore the SSL certificates verification

We have already established that the error is caused by an SSL failure during the handshake between the program and the server.

Luckily the whole problem can be ignored. Yes, you can just use verify=False to ignore the SSL check entirely. To do that you can follow the example bellow.

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

But this has some consequences which should be known to you,  a lot of servers do have a strict policy to deliver responses to requests and this trick may not work.

Using verify=False will remove the benefits given by SSL certificates, especially protection against man-in-the-middle attacks.

If the suggestion above did not work, try to add a header like this.

                                                                       #
requests.get('https://twitter.com', headers = {'User-agent': 'your bot 0.1'}, verify=False)
                                                                       #

I hope this method was enough to help you get rid of this error, try the second method if this one did not work.

Solution 2 : Add verify=’/path/…/certificatefile’ to requests.get()

Instead of ignoring the SSL check a better option is to actually include the path to the certificated. Usually it looks like this but you should replace path with your own path

                                                                       #
'/path/.../certificatefile'
                                                                       #

This is how requests.get should look like.

                                                                       #
requests.get('https://twitter.com', verify='/path/.../certificatefile')
                                                                       #

I hope this solution was enough to help you get rid of this annoying error

The solutions above should be enough to solve the problem, if you like our effort make sure to consider donating to our Kofi account, there is a red button that you can use if you are feeling generous.

Summing-up : 

This error is solved guys, thank you for reading our article, if you have any other errors make sure to search in our site for a solution, so far we are providing solutions for errors in Python, I hope the error : Python Error HTTPS requests produce SSL CERTIFICATE VERIFY FAILED error has been solved for you.

If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/