Python requests SSL and InsecurePlatformWarning

Every now and then, when using Python 2.7 < 2.7.9 and trying to access SSL resources, especially through the requests toolkit, which seems to trigger the issue frequently - but I've seen it on some combinations of pip inside virtualenv as well - you'll get an error or a warning along those lines:

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  


SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see  

or, even worse:

error: SSLError: hostname '' doesn't match either of,  

This is caused by old libraries in python < 2.7.9 and < 3.4. To fix that, just add to your current virtualenv those three packages:

pip install pyOpenSSL ndg-httpsclient pyasn1  

You may need runtime/development packages for python and openssl as well in order for the build to succeed, e.g. python-dev libssl-dev libffi-dev on Ubuntu 14.04.

Alan Franzoni

Read more posts by this author.

Trieste, Italy
comments powered by Disqus