我正尝试为Python安装requests
库(在CentOS6上为2.6.6),
sudo pip install requests[security]
我收到以下错误消息:
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: 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
Collecting requests[security]
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: 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
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: 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
我确保所有系统库都到位
sudo yum install openssl-devel python-devel libffi-devel
那里一切都很好
所以我尝试了
sudo pip install pyopenssl ndg-httpsclient pyasn1
和
sudo pip install --trusted-host pypi.python.org requests
这些也会失败。
由于一些旧代码,我需要坚持使用Python 2.6
您知道这里出了什么问题以及如何解决吗?
PS
我决定降级pip
,结果发现pip
6.1+版本出现了错误。有什么想法吗?
答案 0 :(得分:1)
确实,截至2019年,由于各种限制,由于无法升级系统Python(以及系统提供的openssl),仍有相当多的人面临此问题。
如果您想修复InsecurePlatformWarning .. (Caused by SSLError .. SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version')
,以下解决方案可以帮助使用旧Linux发行版的人:
CentOS6上的Python 2.6.6
在您的特定情况下,虽然官方上可能支持较新的版本,但最新支持正式版Python 2.6的cryptography
版本是cryptography-2.1.1。
第一个 manylinux1 加密软件包,包括自己的Linux的OpenSSL(1.1.0f)共享库绑定,无论您的平台是什么,都已出现在cryptography-2.0版本中。仍正式支持Centos 6.4的最后一种加密技术是1.8.2版,而较新版本仅正式支持CentOS 7.x:https://pypi.org/project/cryptography/#files
请注意,密码版本<2.0没有manylinux1
,并且没有随同发行openssl / ssllib,仅依靠系统提供的版本(当时,它们仅针对具有/有更大的SSL问题)。虽然cryptography-2.0(manylinux1)仍然值得尝试,但是您可能必须在Centos 6.x上本地编译较新的openssl版本(1.0.1-1.1.0),然后再编译cryptography 1.8.2以与其链接:
https://cryptography.io/en/latest/installation/#using-your-own-openssl-on-linux
https://cryptography.io/en/latest/installation/#rhel-centos
还有一个选项可以构建自己的静态链接轮,这些轮将在您自己的系统上运行:
https://cryptography.io/en/latest/installation/#static-wheels
说,
如果仅需要安装requests
库(而不解决臭名昭著的SSLError),特别是在CentOS6上的Python 2.6.6中,并且您将不需要{{1 }},您只需为此使用Centos仓库:
requests
$ yum search requests
或者,您可以通过轮子或从以下站点下载的tar.gz以类似于above-mentioned solution的方式获取并安装$ sudo yum install python26-requests
:
https://pypi.org/project/requests/
请注意,有关PyPI的最新requests
取决于以下Python软件包:
urllib3,idna,chardet,certifi
幸运的是,这四个没有其他依赖关系,可以直接从PyPI获取,方法相同-PyPI的“下载文件” 部分:
https://pypi.org/project/urllib3/
https://pypi.org/project/idna/
https://pypi.org/project/chardet/
https://pypi.org/project/certifi/
您可以下载并尝试安装其最新版本,或者使用“发布历史记录”部分来找到较旧的版本,具体取决于您的用例和特定于系统的要求。
请注意,当今许多Web服务器(包括PyPI)在客户端和服务器后端都需要TLS 1.2支持才能建立HTTPS连接,因此如果您需要这种连接类型,requests
将无法正常工作而不用上述方法修复SSLError(或针对OpenSSL版本1.0.2+编译较新的Python 2.7.9+,在这种情况下,也必须先编译之前编译新的Python,以将其与requests
模块链接)。
答案 1 :(得分:0)
尝试一下:
sudo pip安装请求
不需要[安全]