我使用Python 2.7.3和请求。我通过pip安装了Requests。我相信这是最新的版本。我在Debian Wheezy上运行。

我在过去使用过很多次请求,从来没有遇到过这个问题,但似乎当使用请求进行https请求时,我得到了一个InsecurePlatform异常。

错误提到urllib3,但我没有安装它。我确实安装了它,检查它是否解决了这个错误,但它没有。

/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.

知道我为什么会收到这个吗?我已经检查了文档,正如在错误消息中指定的那样,但是文档说要导入urllib3,要么禁用警告,要么提供证书。


当前回答

对于我没有工作,我需要升级pip....

Debian/Ubuntu

安装依赖关系

sudo apt-get install libpython-dev libssl-dev libffi-dev

升级PIP并安装软件包

sudo pip install -U pip
sudo pip install -U pyopenssl ndg-httpsclient pyasn1

如果你想移除依赖项

sudo apt-get remove --purge libpython-dev libssl-dev libffi-dev
sudo apt-get autoremove

其他回答

这个答案是不相关的,但如果你想摆脱警告,并从请求中得到以下警告:

InsecurePlatformWarning /usr/local/lib/python2.7/ disti -packages/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: true SSLContext对象不可用。这将阻止urllib3正确配置SSL,并可能导致某些SSL连接失败。欲了解更多信息,请参见https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning。

您可以通过在python代码中添加以下行来禁用它:

requests.packages.urllib3.disable_warnings ()

如果你只是想停止不安全的警告,比如:

/usr/lib/python3/dist-packages / urllib3 / connectionpool.py: 794: InsecureRequestWarning:正在发出未经验证的HTTPS请求。添加 强烈建议验证证书。看到的: https://urllib3.readthedocs.org/en/latest/security.html InsecureRequestWarning)

do:

requests.METHOD("https://www.google.com", verify=False)

验证= False

关键是,以下几种都不擅长:

requests.packages.urllib3.disable_warnings ()

or

urllib3.disable_warnings ()

但是,你必须知道,这可能会导致潜在的安全风险。

我没有在生产中使用它,只在一些测试运行中使用。重申一下urllib3文档

如果你知道你在做什么,想要禁用这个和 其他警告

import requests.packages.urllib3
requests.packages.urllib3.disable_warnings()

编辑/更新:

以下也可以:

import logging
import requests

# turn down requests log verbosity
logging.getLogger('requests').setLevel(logging.CRITICAL)

下面是我在Python 3.6上的工作方式:

import requests
import urllib3

# Suppress InsecureRequestWarning: Unverified HTTPS
urllib3.disable_warnings()

我刚刚在CentOS 5服务器上遇到了类似的问题,我在/usr/local中安装了python 2.7.12,上面是一个旧版本的python2.7。目前在此服务器上无法升级到CentOS 6或7。

一些python 2.7模块仍然存在于旧版本的python中,但pip未能升级,因为CentOS 5包不支持更新的加密包。

具体来说,“pip安装请求[security]”失败,因为CentOS 5上的openssl版本是0.9.8e,不再受加密> 1.4.0的支持。

为了解决OPs最初的问题,我做了:

1) pip install 'cryptography<1.3.5,>1.3.0'.  

这安装了与openssl-0.9.8e一起使用的加密1.3.4。密码学1.3.4也足以满足以下命令的需求。

2) pip install 'requests[security]'

此命令现在安装,因为它不会尝试安装加密> 1.4.0。

注意,在Centos 5上,我还需要:

yum install openssl-devel

让密码学得以建立