4 Ways to fix SSL: CERTIFICATE_VERIFY_FAILED in Python

Table of Contents

SSL certificate_verify_failed errors typically occur as a result of outdated Python default certificates or invalid root certificates.

We will cover how to fix this issue in 4 ways in this article.

Error info about CERTIFICATE_VERIFY_FAILED

<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)>

 

Create unverified context in SSL

import ssl
context = ssl._create_unverified_context()
urllib.request.urlopen(req,context=context)

 

Create unverified https context in SSL

import ssl
ssl._create_default_https_context = ssl._create_unverified_context
urllib2.urlopen(“https://google.com”).read()

Use requests module and set ssl verify to false

requests.get(url, headers=Hostreferer,verify=False)

Update SSL certificate with PIP

we can also update our SSL certificate With PIP.  All we would have to do is  to update our SSL certificate directory with the following piece of code:

pip install –upgrade certifi

What this command does is update our system’s SSL certificate directory.

Table of Contents

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn

You might also like