How to Solve – requests.exceptions.SSLError bad handshake Error with Python requests

How to Solve – requests.exceptions.SSLError bad handshake Error with Python requests is an error which happens when the server you access is setup improperly.

This post is my attempt to explain to you why this error occurs and how you can solve it, I will also include multiple solutions that could be considered as alternative fixes to the error.

Exploring the Error : requests.exceptions.SSLError bad handshake Error with Python requests

This is a Python requests error which happens when the server you access is setup improperly.

The error should look like this. Double check in order to avoid mixing between errors.

                                                                       #
requests.exceptions.SSLError: ("bad handshake: Error([('SSL routines', 'ssl3_get_server_certificate', 'certificate verify failed')],)",)
                                                                       #

Bellow are the solutions which worked for me and will help you to successfully solve your problem.

Solution 1 : add the missing chain certificate.

The first solution is to add the missing chain certificate in order to solve the issue.

The problem here is that you are missing an intermediate certificate to the trusted root.

You can add the missing chain certificate using the code bellow.

                                                                       #
import requests
requests.get('https://twitter.com', verify = 'mycerts.pem')
                                                                       #

Do not forget that mycerts.pem should contain the trusted root certificate and the intermediate certificate.

If this solution does not fix your problem you can try the solution bellow

Solution 2 : use verify=False in order to skip the SSL verification.

Another alternative solution is to use verify=False in order to skip the SSL verification.

You can do that by using the code bellow.

                                                                       #
print(requests.get(url, proxies,verify = False))
                                                                       #

The solution should be enough, please try the first solution if this fails.

If this article has been useful for your particular case, consider donating to our Kofi account, there is a red button at the top of this page.

Summing-up

The article is over, I hope I have been able to help you solve this error or at least guide you in the right direction, check out other solutions to different errors you can do that by using the search bar on top of this page.

Keep learning, keep coding guys, cheers. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/