gpt4 book ai didi

python - 由于证书过时,pip 在 MacOS 上因 SSLError 失败 - 如何恢复?

转载 作者:行者123 更新时间:2023-11-28 22:19:08 26 4
gpt4 key购买 nike

在 MacOS (10.11.6) 上使用 pip 搜索或安装包时,我收到类似于下面再现的 SSL 错误。

python2和python3都会出现这个问题。我通过 www.python.org 获得了版本(2.7.14 和 3.6.5)作为框架。 pip 的版本是 9.0.1。这个问题是新出现的(2018 年 4 月),似乎与 OSX 的更新有关。

如何从这个问题中恢复?

$ pip2 search numpy

Exception:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/commands/search.py", line 45, in run
pypi_hits = self.search(query, options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/commands/search.py", line 62, in search
hits = pypi.search({'name': query, 'summary': query}, 'or')
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1243, in __call__
return self.__send(self.__name, args)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1602, in __request
verbose=self.__verbose
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/download.py", line 775, in request
headers=headers, stream=True)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 522, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/download.py", line 386, in request
return super(PipSession, self).request(method, url, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 475, in request
resp = self.send(prep, **send_kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 596, in send
r = adapter.send(request, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/_vendor/cachecontrol/adapter.py", line 47, in send
resp = super(CacheControlAdapter, self).send(request, **kw)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/_vendor/requests/adapters.py", line 497, in send
raise SSLError(e, request=request)
SSLError: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:661)

最佳答案

有两种方法可以从这个问题中恢复。

解决方案 1。正如可以阅读here , Python.org 站 pip 停止了对旧 TLS 版本的支持,这打破了 pip < 9.0.3 .提供了新版本的 pip,但由于不能简单地通过损坏的 pip 进行更新,因此必须引导安装。这对我有用:

# For python2
curl https://bootstrap.pypa.io/get-pip.py | python2
# For python3 (haven't tested this myself)
curl https://bootstrap.pypa.io/get-pip.py | python3

这些命令的功劳可以追溯到 this SO post .

解决方案 2。对于 Python 3.6 框架,脚本 Install Certificates.command/Applications/Python 3.6/ 下部署和安装.执行它解决了问题,但仅限于 pip3 .

关于python - 由于证书过时,pip 在 MacOS 上因 SSLError 失败 - 如何恢复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49998942/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com