Python PIP 和 InsecurePlatformWarning

Jac*_*ife 5 python ssl pip python-requests

我正在尝试requests为 Python(CentOS6 上的 2.6.6)安装库作为

sudo pip install requests[security]
Run Code Online (Sandbox Code Playgroud)

我收到这些错误消息:

/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
Run Code Online (Sandbox Code Playgroud)

我确保所有系统库都到位

sudo yum install openssl-devel python-devel libffi-devel
Run Code Online (Sandbox Code Playgroud)

那里一切都很好

所以我试过了

sudo pip install pyopenssl ndg-httpsclient pyasn1
Run Code Online (Sandbox Code Playgroud)

sudo pip install --trusted-host pypi.python.org requests
Run Code Online (Sandbox Code Playgroud)

这些也失败了。

由于一些旧代码,我需要坚持使用 Python 2.6

知道这里出了什么问题以及如何解决吗?

聚苯乙烯

我决定降级pip,结果发现pip6.1+ 版本出现错误。对此有何想法?

Ale*_* C. 2

事实上,截至2019年,相当多的人仍然面临这个问题,因为他们由于各种限制而无法升级系统Python(以及系统提供的openssl)。

如果您想修复该问题InsecurePlatformWarning .. (Caused by SSLError .. SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version'),以下解决方案可以帮助使用旧 Linux 发行版的用户:

无法在 Ubuntu Linux 中使用 pip 安装 Python 包:InsecurePlatformWarning、SSLError、tlsv1 警报协议版本

CentOS6 上的 Python 2.6.6

在您的具体情况下,cryptography官方支持 Python 2.6 的最后一个版本是 cryptography-2.1.1,尽管较新的版本可能会工作。第一个包含针对 Linux 的 OpenSSL (1.1.0f) 共享库绑定的Manylinux1加密包已出现在 cryptography-2.0 版本中,无论您的平台是什么。仍正式支持 Centos 6.4 的最后一个密码学版本是 1.8.2,而较新的版本仅正式支持 CentOS 7.x:https: //pypi.org/project/cryptography/#files

请注意,<2.0 的加密版本没有manylinux1也没有附带 openssl/ssllib,仅依赖于系统提供的 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

也就是说,

如果您需要的只是安装requestslib(不解决臭名昭著的 SSLError),特别是在 CentOS6 上的 Python 2.6.6 中,并且您不需要来自 的 TLS 1.2 协议支持requests,那么您可以简单地使用 Centos 存储库:

$ yum search requests
$ sudo yum install python26-requests

或者,您可以通过与上述解决方案requests类似的方式从轮子或从下载的 tar.gz 获取 并安装:https: //pypi.org/project/requests/

请注意,PyPI 的最新版本requests取决于以下 Python 包:urllib3、idna、chardet、certifi

幸运的是,这四个没有其他依赖项,可以直接从 PyPI 获取,方式相同 - PyPI 上的“下载文件”部分:https:
//pypi.org/project/urllib3/
https://pypi.org/项目/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之前也必须编译该版本,以将ssl模块与其链接)。