Python InsecurePlatformWarning:真正的 SSLContext 对象不可用。这会阻止 urllib3 正确配置 SSL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29134512/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately
提问by user4525298
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. I tried to install urllib3 and requests[security] as some other thread suggests, I still got the same error.
我的 python 版本是 2.7.3。我尝试按照其他一些线程的建议安装 urllib3 和 requests[security],但我仍然遇到相同的错误。
Wonder if anyone can provide some tips?
想知道是否有人可以提供一些提示?
回答by raittes
If you are not able to upgradeyour 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
回答by nathan-m
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
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