首页 > 解决方案 > 使用 twine 将 python 包上传到自定义注册表时出现 SSL 错误

问题描述

当尝试将 python 自定义包上传到我们的内部注册表时,它失败并出现以下错误。

 urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='custom-nexus.com’, port=443): Max retries exceeded with url: /repository/pypi-internal/ (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))

但是通过 curl 访问时,相同的 url 可以正常工作。使用 curl -v 选项发现使用的 ca-bundle 位于 /etc/pki/tls/certs/ca-bundle.crt 位置

所以尝试使用 --cert 选项在 twine 上传命令中提供这个。但随后它也无法正常工作并因同样的错误而失败。

twine upload --config-file .pypirc   --cert /etc/pki/tls/certs/ca-bundle.crt  -r pypi dist/*

使用的 Python 版本是 3.6。请在下面的库版本列表中找到。

certifi==2020.4.5
setuptools==46.1.3
wheel==0.34.2
twine==3.1.1
pyOpenSSL==19.1.0

标签: python-3.xssltwine

解决方案


由于某种原因,即使在使用 --cert 选项提供证书后,它也对我不起作用。证书可能有问题。然后我遇到了下面的黑客在 python 请求库中跳过 ssl 验证

对导入的模块禁用 Python 请求 SSL 验证

(对于任何不知道的人,引擎盖下的 TWINE 也使用 python 请求库)

在此之后,我尝试了以下命令并且它有效!

export CURL_CA_BUNDLE="" && twine upload ...

推荐阅读