我有仍在运行 Python 2.7.6 的旧生产服务器。我们有一个从 ubuntu 14.04 的 docker 映像构建的本地环境,旨在复制该环境(一旦安装了所有东西,一切仍然可以在那里工作。)由于 PyPi 放弃了非 SNI 支持,创建此环境的打包程序构建脚本最近显然停止工作。
我尝试使用文档中的 get-pip.py
下载 pip:
wget -c https://bootstrap.pypa.io/pip/2.7/get-pip.py
python2 get-pip.py
这给了我以下警告:
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
/tmp/tmpBb3LJu/pip.zip/pip/_vendor/urllib3/util/ssl_.py:424: SNIMissingWarning: An HTTPS request has been made, but the SNI (Server Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
/tmp/tmpBb3LJu/pip.zip/pip/_vendor/urllib3/util/ssl_.py:164: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
ERROR: Could not find a version that satisfies the requirement pip<21.0 (from versions: none)
ERROR: No matching distribution found for pip<21.0
建议的解决方案是使用 pip
升级 urllib3
https://serverfault.com/questions/866062/easy-install-and-pip-fail-with-ssl-warnings
我没有 pip,所以我使用
安装了旧版本apt-get install python-pip
这将安装 pip 1.5.4
当我尝试 pip install "urllib3[secure]"
时,我得到以下信息:
Requirement already satisfied (use --upgrade to upgrade): urllib3[secure] in /usr/lib/python2.7/dist-packages
Installing extra requirements: 'secure'
Cleaning up...
如果我尝试 pip install "urllib3[secure]" --upgrade
或 pip install --index-url https://pypi.python.org/simple/ --upgrade pip
我得到:
Cannot fetch index base URL https://pypi.python.org/simple/
Could not find any downloads that satisfy the requirement urllib3[secure] in /usr/lib/python2.7/dist-packages
Downloading/unpacking urllib3[secure]
Cleaning up...
No distributions at all found for urllib3[secure] in /usr/lib/python2.7/dist-packages
Storing debug log for failure in /root/.pip/pip.log
(pip 消息反映的是 pip,而不是 urllib3[secure])
当我尝试使用 pip 1.5 安装 uWSGI
pip install uWSGI
我得到以下信息:
Downloading/unpacking uWSGI
Cannot fetch index base URL https://pypi.python.org/simple/
Could not find any downloads that satisfy the requirement uWSGI
Cleaning up...
No distributions at all found for uWSGI
Storing debug log for failure in /root/.pip/pip.log
升级 pip 在这里也不起作用
Downloading/unpacking uWSGI==2.0.18 (from -r /root/requirements.txt (line 1))
Cannot fetch index base URL https://pypi.python.org/simple/
Could not find any downloads that satisfy the requirement uWSGI==2.0.18 (from -r /root/requirements.txt (line 1))
Cleaning up...
No distributions at all found for uWSGI==2.0.18 (from -r /root/requirements.txt (line 1))
Storing debug log for failure in /root/.pip/pip.log
重新安装 pip 不起作用:
python -m pip install -U --force-reinstall pip
给我:
Downloading/unpacking pip
Cannot fetch index base URL https://pypi.python.org/simple/
Could not find any downloads that satisfy the requirement pip
Cleaning up...
No distributions at all found for pip
Storing debug log for failure in /root/.pip/pip.log
如果我打开 /root/.pip/pip.log
,我会看到以下内容:
Downloading/unpacking pip
Getting page https://pypi.python.org/simple/pip/
Could not fetch URL https://pypi.python.org/simple/pip/: 403 Client Error: [[[!!! BREAKING CHANGE !!!]]] Support for clients that do not support Server Name Indication is temporarily disabled and will be permanently deprecated soon. See https://status.python.org/incidents/hzmjhqsdjqgb and https://github.com/pypa/pypi-support/issues/978 [[[!!! END BREAKING CHANGE !!!]]]
The link 表示已取消 SNI 支持:
For users of Python 2.7.{0...8}
Upgrading to the last Python 2.7 release is an option.
However, note that Python 2.7 series itself is now End of Life and support in pip was dropped with version 21.0.
For users of Python 2.6.x and lower:
Neither the Python core developers, or pip maintainers support Python 2.6 and below.
If someone is aware of a work around for this issue (SNI support specifically) they are welcome to share it here for others.
There is no recommended solution from the PyPI team.
如何为新开发人员设置本地环境以处理我们的旧应用程序?我已经创建了一个新的 Python 3 开发服务器和本地环境,但是我还需要一段时间才能推出临时环境和实时环境,将所有内容都移过去并进行测试。
答案 0 :(得分:2)
正如消息所述,截至 2021 年 5 月 6 日,PyPi 具有适用于 Python <2.7.9 的 discontinued support。如果您运行的是 < 2.7.9 版本并且您无法升级到更新版本的 Python,那么您的唯一的选择是从 PyPi 手动下载轮子。
这些是我需要对构建脚本进行的修改以使其正常工作:
我需要安装 software-properties-common
和 gcc
apt-get install -y software-properties-common gcc
然后我下载了 (setuptools](https://pypi.org/project/setuptools/44.1.1/#files) 并解压并安装了它:
python ./setuptools-44.1.1/setup.py install
接下来,我下载了 pip 并将其添加到名为 wheels
的文件夹中。然后我可以使用whl文件运行pip来获取pip
python ./wheels/pip-20.3.4-py2.py3-none-any.whl/pip install --no-index --find-links ./wheels/ pip --ignore-installed
建议使用 Ubuntu 16.04 和 Python 2.7.17 构建一个 Docker 容器,并使用它来下载包。
pip download -r requirements.txt
但是软件包的版本是错误的,所以我最终浏览了 requirements.txt 并从 PyPi 手动下载了每个软件包并将其添加到 wheels
文件夹中。正在运行的实例很有用,因此您可以运行 pip freeze
或查看 requirements.txt
文件以获取所需的所有软件包的版本号。
现在我可以使用 pip,我可以安装我的其他软件包了:
python pip install --no-index --find-links ./wheels/ -r /root/requirements.txt
这发现了一些我还没有下载软件包的依赖项,所以我不得不下载这些依赖项并将它们添加到 wheels
文件夹中。我发现还有一些其他东西需要与我最初下载的版本不同,一些软件包依赖于 pbr,还有更多需要 wheel:
pip install --no-index --find-links ./wheels/ pbr==5.5.1 wheel==0.36.2
我还需要下载 cMake 并将其添加到 wheels
文件夹
之后我可以安装我的requirements.txt
:
pip install --no-index --find-links ./wheels/ -r /root/requirements.txt --ignore-installed
答案 1 :(得分:1)
可能会迟到,但在我尝试使用 Python 2.7.6(缺乏 SNI 支持)发出 HTTPS 请求时发生了类似的事情。这在我工作的远程 Web 服务器上造成了很多问题。
寻找答案我尝试安装 urllib3[secure]
并进入了一个漏洞,因为 pip 抱怨缺乏 SNI 支持来安装这个和其他软件包。
我发现了这个 StackOverflow answer,它帮助我安装了使 Python 2.7.6 和 pip 本身支持 SNI 以及安装 urllib[secure]
所需的依赖项。
您需要创建一个包含所需轮子的文件夹(例如使用 wget 从 PyPi 下载它们):
<块引用>pip、asn1crypto、enum34、idna、6、ipaddress、pyOpenSSL、cffi、 密码轮;还有 pycparser(一个非轮子,它将是一个 tar.gz)
确保您下载的轮子支持 Python 2.7,并且在其他轮子之前安装 pip。
在原始答案中,它声明您可以使用 python -m OpenSSL.debug
来验证一切正常(ModuleNotFoundError 表示未安装 pyOpenSSL 包)。您还可以使用 pip -V
检查新的 pip 版本是否也已正确安装。
更新 pip 并安装这些依赖项后,我能够安装 urllib3[secure] 并从 python 和 pip 获得 SNI 支持。
祝你好运!