python requests module ssl certificate_verify_failed

Python Requests Module SSL Certificate Verify Failed

SSL Certificate Verify Failed is a common error that occurs while using the Python Requests module. It means that the SSL certificate of the website that you are trying to connect to is not verified or trusted by the system. There are a few ways to fix this error:

1. Disable SSL Verification

The easiest solution is to disable SSL verification by setting the verify parameter to False.


import requests

response = requests.get('https://example.com', verify=False)
print(response.content)

2. Provide a Custom CA Bundle

You can provide a custom CA bundle file that contains the trusted root certificates by setting the verify parameter to the location of the custom bundle file.


import requests

response = requests.get('https://example.com', verify='/path/to/custom/bundle.pem')
print(response.content)

3. Trust the Certificate Manually

If you trust the SSL certificate of the website, you can manually trust it by adding it to the system's trusted root certificates.

First, download the SSL certificate of the website by running the following command:


openssl s_client -showcerts -connect example.com:443 

This will print out the SSL certificate chain. Copy the certificate of the website (not the root or intermediate certificates) to a file named example.crt

Next, run the following command to add the certificate to the trusted root certificates:


sudo cp example.crt /usr/local/share/ca-certificates/example.crt
sudo update-ca-certificates 

After running these commands, the SSL certificate of the website should be trusted and you should be able to use the Python Requests module without any errors.