由于操作系统错误而无法安装软件包:[SSL:CERTIFICATE_VERIFY_FAILED]证书验证失败:自签名证书(_ssl.c:1131)

问题描述 投票:0回答:2

我一直试图通过阅读这里的不同答案来解决这个问题,但没有一个答案被证明是“解决方案”,所以我会尝试简要解释我的情况,以便你们可以给我一个线索。 问题是,当我尝试运行

pip install <package>
时,它会以以下警告开始(只是为了向您展示,使用 fastapi 作为示例):

  WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1131)'))': /packages/4f/46/226355e82ccb4be82e06269e9a546f16c1d87fbda2286fb5d36a1c31af9e/fastapi-0.75.0-py3-none-any.whl
  WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1131)'))': /packages/4f/46/226355e82ccb4be82e06269e9a546f16c1d87fbda2286fb5d36a1c31af9e/fastapi-0.75.0-py3-none-any.whl
  WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1131)'))': /packages/4f/46/226355e82ccb4be82e06269e9a546f16c1d87fbda2286fb5d36a1c31af9e/fastapi-0.75.0-py3-none-any.whl
  WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1131)'))': /packages/4f/46/226355e82ccb4be82e06269e9a546f16c1d87fbda2286fb5d36a1c31af9e/fastapi-0.75.0-py3-none-any.whl

最后是:

ERROR: Could not install packages due to an OSError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/4f/46/226355e82ccb4be82e06269e9a546f16c1d87fbda2286fb5d36a1c31af9e/fastapi-0.75.0-py3-none-any.whl (Caused by SSLError(SSLCertVerificationError(1,'[SSL:CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate(_ssl.c:1131)')))

我尝试的第一件事是

pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org <package>
,但它只给了我另一个错误。所以我开始阅读有关 SSL 证书的内容,当错误显示“自签名证书”时,这意味着我尝试连接的服务器,他的证书是由服务器本身或提供链签名的实体自签名的不在浏览器的白名单中。 事实上也是如此!. 但是当我使用一些在线工具检查该网站的证书时

一切似乎都很可靠

背景:

我上次下载软件包是大约一个月前(我昨天才意识到这一点)
  • Python 版本:3.8.10 / pip 版本:21.1.1
  • Windows 10 / 个人计算机和家庭网络(无公司权限)
  • 这种情况发生在每个级别:当尝试构建 docker 时,在
  • venv
  • 内部以及系统级别(venv 外部)
    
    
  • 所以,我真的不知道从哪里开始。是我的本地机器有问题吗?,是 pythonhosted 的问题吗?,我是否把事情搞混了?,我应该卸载/重新安装 Python 吗?

python ssl cacerts
2个回答
7
投票

pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org <package-name>

例如:

pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org pandas



0
投票

pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org <package_name>

或永久:

pip config set global.trusted-host "pypi.org files.pythonhosted.org pypi.python.org"

如果遇到问题,最好的办法是创建一个 pip.ini 文件(Unix 上为 pip.conf)。您需要做的就是添加以下内容:

[global] trusted-host = pypi.python.org pypi.org files.pythonhosted.org

如果您不确定在哪里可以找到 pip.ini 文件或如何创建它,请不要担心。有大量资源可以帮助您。只需查看 pip 配置文件,您就会找到所需的一切。 
点子配置

© www.soinside.com 2019 - 2024. All rights reserved.