我使用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,要么禁用警告,要么提供证书。


当前回答

在我的例子中,我正在使用一个旧的ubuntu可靠映像,并试图安装python dateutil。我必须首先用以下方法将python升级到2.7.12:

add-apt-repository -y ppa:fkrull/deadsnakes-python2.7
apt-get -y update
apt install -y --force-yes python2.7-minimal
pip install python-dateutil

其他回答

对于我没有工作,我需要升级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

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

/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 ()

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

上周,我在Ubuntu 14.04 (Python 2.7.6)上进行了apt-get dist-upgrade,其中包括libssl1.1:amd64。

由于我从cron作业运行certbot-auto renew,所以我还使用——no-self-upgrade来减少不定期的维护。这似乎是问题的根源。

要修复这个错误,我所需要做的就是成为根用户(使用su的登录开关),并让certbot-auto自己升级。即:

sudo su --login
/usr/local/bin/certbot-auto renew 
# ... Upgrading certbot-auto 0.8.1 to 0.18.2... blah blah blah ...

而不是通常从root的crontab运行:

5 7 * * * /usr/local/bin/certbot-auto renew --quiet --no-self-upgrade

在此之后,让sencrypt renwals再次正常运行。

在我的例子中,我正在使用一个旧的ubuntu可靠映像,并试图安装python dateutil。我必须首先用以下方法将python升级到2.7.12:

add-apt-repository -y ppa:fkrull/deadsnakes-python2.7
apt-get -y update
apt install -y --force-yes python2.7-minimal
pip install python-dateutil

Requests 2.6为2.7.9以前版本的python用户引入了此警告,只有现有的SSL模块可用。

假设你不能升级到较新的python版本,这将安装最新的python SSL库:

pip install --upgrade ndg-httpsclient 

然而,在一些没有pyOpenSSL的构建依赖的系统上,这可能会失败。在debian系统上,在上面的pip命令之前运行这个命令应该足以让pyOpenSSL构建:

apt-get install python-dev libffi-dev libssl-dev