问题描述
尝试使用以下代码通过 python 请求执行 REST GET,但出现错误.
Tried to perform REST GET through python requests with the following code and I got error.
代码片段:
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 和 requests[security],但仍然遇到相同的错误.
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?
推荐答案
文档给出了一个公平的指标需要什么.,但是requests
允许我们跳过几个步骤:
The docs give a fair indicator of what's required., however requests
allow us to skip a few steps:
您只需要安装 security
附加包 (感谢@admdrew 指出)
You only need to install the security
package extras (thanks @admdrew for pointing it out)
$ pip install requests[security]
或者,直接安装它们:
$ pip install pyopenssl ndg-httpsclient pyasn1
如果您使用的是 ubuntu,安装 pyopenssl
时可能会遇到问题,您将需要以下依赖项:
If you're on ubuntu, you may run into trouble installing pyopenssl
, you'll need these dependencies:
$ apt-get install libffi-dev libssl-dev
这篇关于InsecurePlatformWarning:真正的 SSLContext 对象不可用.这会阻止 urllib3 正确配置 SSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!