InsecurePlatformWarning:真正的SSLContext对象不可用。这可以防止urllib3正确配置SSL

时间:2015-03-18 23:21:21

标签: python rest ssl

尝试使用以下代码通过python请求执行REST GET,我收到错误。

代码片段:

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)

错误:

/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

我的python版本是2.7.3。我尝试安装urllib3并请求[安全],因为其他线程建议,我仍然有同样的错误。

想知道是否有人可以提供一些提示?

2 个答案:

答案 0 :(得分:546)

The docs give a fair indicator of what's required.,但requests允许我们跳过几个步骤:

您只需安装security package extras(感谢@admdrew指出)

$ pip install requests[security]

或直接安装:

$ pip install pyopenssl ndg-httpsclient pyasn1

Requests will then automatically inject pyopenssl into urllib3


如果您使用的是ubuntu,安装pyopenssl时可能会遇到问题,您需要这些依赖项:

$ apt-get install libffi-dev libssl-dev

答案 1 :(得分:69)

如果您无法升级您的Python版本为2.7.9,并且想要取消警告,

您可以将“请求”版本降级为2.5.3:

pip install requests==2.5.3

Bugfix disclosure / Warning introduced in 2.6.0