This is a followup to SSLError using requests for python:
I have just installed requests on a Mac OSX 10.8.5. My first attempt at doing requests.get failed on missing certificate:
SSLError: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
The thread above says to look for
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/cacert.pembut actually I don't even have a.../site-packages/requestsdirectory. It's not clear to me if this should have been added by the installation (I usedpip)Further threads and the
requestsdocs say to installcertifi, so I did. But now I get a different error:python -c 'import requests; requests.get("https://api.github.com/events")' /usr/lib/anaconda/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning Traceback (most recent call last): ... File "/usr/lib/anaconda/lib/python2.7/site-packages/requests/adapters.py", line 431, in send raise SSLError(e, request=request) requests.exceptions.SSLError: [Errno 1] _ssl.c:504: error:0D0890A1:asn1 encoding routines:ASN1_verify:unknown message digest algorithm
Thanks!
Notice that you're using
HTTPS. As mentioned in the Requests manualHere are few ways to fix that:
Update OpenSSL (probably will solve your problem)
Taken from here:
Check your
opensslversion byIf you have a smaller version than
OpenSSL0.9.8o, you have to update its version (OS X):If that doesn't work, try this way:
opensslinstalled beforeOS X 10.10.3and reinstalling it fixes itopenssl, remove its folder from your hard-disk and install it again (the updated version)Install
certifiTaken from here
In other word, try to install
certifi, if you haveRequest 2.4.0or newer:Hopefully, this will fix the problem.
Use different version of OpenSSL and Requests
Looking into it using Google, I have found that there is a problem with OpenSSL in Python 2:
However, I am using
Python 2.7.6,Requests 2.2.1andOpenSSL 1.0.1f 6 Jan 2014and everything runs correctly.Pass the certificate
In other cases, you may need to tell
requests.getthe path to the certificate file, if the host's certificate was signed by you.Set the verify argument to False (NOT RECOMMENDED!)
In case you want to avoid the certificate verification, you have to pass
verify=Falseto therequest.getmethod.or from
script.pyfile:terminal:
Important: Very bad idea; You can be MITM attacked, which is a critical security vulnerability.