Skip to content

Instantly share code, notes, and snippets.

Created December 21, 2022 19:26
What would you like to do?
Django Recaptcha fix for SSL:CERTIFICATE_VERIFY_FAILED unable to get local issuer
There are likely a few fixes for this but you are likely to see this error
if your app needs to reach out to an https server (in this case
and it cannot verify the ssl certificate.
The certifi package ( ) provides a
curated collection of Root Certificates that avoids this.
pip install certifi - then in your settings you just need to set
the environmental variable for REQUESTS_CA_BUNDLE and SSL_CERT_FILE.
This can be done in your
On pip upgrades you may need to specify the location of the cacert by doing:
python -c "import certifi; print(certifi.where())"
note the path
and then do pip install -r requirements.txt --cert={path from above}
# Generally to test
# import os
# import certifi
# import urllib
# urllib.request.urlopen('') will fail
# then
# >>> os.environ["REQUESTS_CA_BUNDLE"] = certifi.where()
#>>> os.environ["SSL_CERT_FILE"]=certifi.where()
# now the request will work
import os
import certifi
os.environ["REQUESTS_CA_BUNDLE"] = certifi.where()
os.environ["SSL_CERT_FILE"] = certifi.where()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment