python – InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately

The Question :

331 people think this question is useful

Tried to perform REST GET through python requests with the following code and I got error.

Code snip:

import requests
header = {'Authorization': 'Bearer...'}
url = az_base_url + az_subscription_id + '/resourcegroups/Default-Networking/resources?' + az_api_version
r = requests.get(url, headers=header)

Error:

/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:79: 
          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

My python version is 2.7.3. I tried to install urllib3 and requests[security] as some other thread suggests, I still got the same error.

Wonder if anyone can provide some tips?

The Question Comments :
  • Did you read the link (urllib3.readthedocs.org/en/latest/…)? It gives two suggestions: either upgrade to at least Python 2.7.9 or use pyOpenSSL.
  • Thanks for your comments. I tried to install pyOpenSSL but failed. Let me try to upgrade to 2.7.9 and see if that fix the problem.
  • @user4525298 did by updgrading 2.7.9 solve your problem?
  • @NedDeily: the link is now broken
  • @Sheena: thanks. urllib3.readthedocs.io/en/latest/…

The Answer 1

553 people think this answer is useful

The docs give a fair indicator of what’s required., however requests allow us to skip a few steps:

You only need to install the security package extras (thanks @admdrew for pointing it out)

$ pip install requests[security]

or, install them directly:

$ pip install pyopenssl ndg-httpsclient pyasn1

Requests will then automatically inject pyopenssl into urllib3


If you’re on ubuntu, you may run into trouble installing pyopenssl, you’ll need these dependencies:

$ apt-get install libffi-dev libssl-dev

The Answer 2

70 people think this answer is useful

If you are not able to upgrade your Python version to 2.7.9, and want to suppress warnings,

you can downgrade your ‘requests’ version to 2.5.3:

pip install requests==2.5.3

Bugfix disclosure / Warning introduced in 2.6.0

Tags:, ,

Add a Comment