尝试使用以下代码通过 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 和 requests[security],但仍然遇到相同的错误。
想知道是否有人可以提供一些提示?
最佳答案
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
关于python - InsecurePlatformWarning : A true SSLContext object is not available. 这会阻止 urllib3 正确配置 SSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29134512/