This question already has an answer here: 这个问题在这里已有答案:
Tried to perform REST GET through python requests with the following code and I got error. 尝试使用以下代码通过python请求执行REST GET,我收到了错误。
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. 我的python版本是2.7.3。 I tried to install urllib3 and requests[security] as some other thread suggests, I still got the same error. 我尝试安装urllib3并请求[安全],因为其他线程建议,我仍然有同样的错误。
Wonder if anyone can provide some tips? 想知道是否有人可以提供一些提示?
#1楼
#2楼
If you are not able to upgrade your Python version to 2.7.9, and want to suppress warnings, 如果您无法将Python版本升级到2.7.9,并且想要禁止警告,
you can downgrade your 'requests' version to 2.5.3: 您可以将“请求”版本降级到2.5.3:
pip install requests==2.5.3
Bugfix disclosure / Warning introduced in 2.6.0 2.6.0中引入了 Bugfix披露 / 警告
#3楼
The docs give a fair indicator of what's required. 文档给出了所需要的公平指标。 , however requests
allow us to skip a few steps: 但是requests
允许我们跳过几个步骤:
You only need to install the security
package extras (thanks @admdrew for pointing it out) 您只需安装security
包附加功能 (感谢@admdrew指出)
$ pip install requests[security]
or, install them directly: 或者,直接安装它们:
$ pip install pyopenssl ndg-httpsclient pyasn1
Requests will then automatically inject pyopenssl
into urllib3
请求将自动将pyopenssl
注入urllib3
If you're on ubuntu, you may run into trouble installing pyopenssl
, you'll need these dependencies: 如果您使用的是ubuntu,则可能在安装pyopenssl
遇到问题,您需要这些依赖项:
$ apt-get install libffi-dev libssl-dev