I have a root CA certificate installed on my machine and all is fine when issuing a requests when using the system install of the requests library:
$ python -c 'import requests; print requests.get("https://example.com")'
<Response [200]>
However if I issue the same request from within a virtual environment the certificate verification fails:
$ python -c 'import requests; print requests.get("https://example.com")'
requests.exceptions.SSLError: [Errno 1] _ssl.c:510: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Using requests.certs.where
I can see the system install uses the systems CA bundle and the virtual environment uses the CA bundle shipped with requests:
$ python -c "import requests; print requests.certs.where()"
/etc/ssl/certs/ca-certificates.crt
$ (venv) python -c "import requests; print requests.certs.where()"
.../venv/local/lib/python2.7/site-packages/requests/cacert.pem
Is there another solution to picking up the system certs without providing the path on each request when using virtualenv
, i.e:
>>> requests.get("https://example.com" verify="/etc/ssl/certs/ca-certificates.crt")
Activating a virtual environment Before you can start installing or using packages in your virtual environment you'll need to activate it. Activating a virtual environment will put the virtual environment-specific python and pip executables into your shell's PATH .
Method 1: Passing verify=False to request method Along with the URL also pass the verify=False parameter to the method in order to disable the security checks.
A virtual environment is a tool that helps to keep dependencies required by different projects separate by creating isolated python virtual environments for them. This is one of the most important tools that most of the Python developers use.
If you want to insert a specific CA certificate to your CA bundle of virtualenv, you can just append to it:
openssl x509 -in $specific_ca.crt -text >> $virtualenv/lib/python2.7/site-packages/certifi/cacert.pem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With