尝试使用以下代码通过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和请求[安全]作为一些其他线程建议,我仍然得到相同的错误。

不知道是否有人能提供一些建议?


如果您无法将Python版本升级到2.7.9,并希望消除警告,

你可以把你的“请求”版本降级到2.5.3:

pip install requests==2.5.3

2.6.0中引入的错误修正披露/警告

文档给出了一个公平的指标,要求什么。,但是请求允许我们跳过几个步骤:

你只需要安装安全包附加(谢谢@admdrew指出)

$ pip install requests[security]

或者直接安装:

$ pip install pyopenssl ndg-httpsclient pyasn1

请求会自动将pyopenssl注入urllib3


如果你在ubuntu上,你可能会在安装pyopenssl时遇到麻烦,你需要这些依赖项:

$ apt-get install libffi-dev libssl-dev