SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书)'

Posted

技术标签:

【中文标题】SSLError(SSLCertVerificationError(1, \'[SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书)\'【英文标题】:SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate)'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书)' 【发布时间】:2021-07-20 09:39:06 【问题描述】:

您好,我在构建 python 图像时遇到问题

错误说,

> [8/9] RUN pip install -r requirements.txt:
#12 9.084 Collecting azure-iot-device~=2.0.0
#12 9.262   WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1091)'))': /packages/3f/a2/380aa87ade47fcdc8b39503bb36f0a3ab16a9667b7134219b021c2ae5633/azure_iot_device-2.0.1-py2.py3-none-any.whl
#12 9.886   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: unable to get local issuer certificate (_ssl.c:1091)'))': /packages/3f/a2/380aa87ade47fcdc8b39503bb36f0a3ab16a9667b7134219b021c2ae5633/azure_iot_device-2.0.1-py2.py3-none-any.whl
#12 11.01   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: unable to get local issuer certificate (_ssl.c:1091)'))': /packages/3f/a2/380aa87ade47fcdc8b39503bb36f0a3ab16a9667b7134219b021c2ae5633/azure_iot_device-2.0.1-py2.py3-none-any.whl
#12 13.15   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: unable to get local issuer certificate (_ssl.c:1091)'))': /packages/3f/a2/380aa87ade47fcdc8b39503bb36f0a3ab16a9667b7134219b021c2ae5633/azure_iot_device-2.0.1-py2.py3-none-any.whl
#12 17.32   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: unable to get local issuer certificate (_ssl.c:1091)'))': /packages/3f/a2/380aa87ade47fcdc8b39503bb36f0a3ab16a9667b7134219b021c2ae5633/azure_iot_device-2.0.1-py2.py3-none-any.whl
#12 17.49 ERROR: Could not install packages due to an OSError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/3f/a2/380aa87ade47fcdc8b39503bb36f0a3ab16a9667b7134219b021c2ae5633/azure_iot_device-2.0.1-py2.py3-none-any.whl (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1091)')))
#12 17.49
#12 19.10 WARNING: You are using pip version 21.0.1; however, version 21.1 is available.
#12 19.10 You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
------
executor failed running [/bin/sh -c pip install -r requirements.txt]: exit code: 1

但是在升级点子时,同样的错误显示。

错误:由于 EnvironmentError 无法安装软件包:HTTPSConnectionPool(host='files.pythonhosted.org', port=443): url 超出最大重试次数:/packages/ac/cf/0cc542fc93de2f3b9b53cb979c7d1118cffb93204afb46299a9f858e113f/pip-21.1- py3-none-any.whl (由 SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书 (_ssl.c:1123)')))

我试过了, 在我的 docker 文件中运行 pip install --trusted-host=pypi.python.org --trusted-host=pypi.org --trusted-host=files.pythonhosted.org -r requirements.txt,但它对我没有帮助。

我试过了,卸载所有 python 解释器并重新安装,但结果相同。

我们没有使用代理服务器,我可以正常 ping files.pythonhosted.org

希望有人能在这方面帮助我。谢谢。

【问题讨论】:

请看这篇文章:SSL: CERTIFICATE_VERIFY_FAILED 和 Unable to get local issuer certificate when using requests in python。 【参考方案1】:

您可以尝试像下面这样添加受信任的主机。

pip install -r requirements.txt --trusted-host files.pythonhosted.org --trusted-host pypi.org --trusted-host pypi.python.org

【讨论】:

【参考方案2】:

验证证书是否到位。

~ $ python3.7 -c "import ssl; print(ssl.get_default_verify_paths())"
DefaultVerifyPaths(
cafile='/etc/pki/tls/cert.pem', 
capath='/etc/pki/tls/certs', 
openssl_cafile_env='SSL_CERT_FILE', 
openssl_cafile='/etc/pki/tls/cert.pem', 
openssl_capath_env='SSL_CERT_DIR', 
openssl_capath='/etc/pki/tls/certs')

【讨论】:

嗨@Sandeep Kumar Chenna 这里是结果。 DefaultVerifyPaths(cafile=None, capath=None, openssl_cafile_env='SSL_CERT_FILE', openssl_cafile='C:\\Program Files\\Common Files\\SSL/cert.pem', openssl_capath_env='SSL_CERT_DIR', openssl_capath='C:\ \Program Files\\Common Files\\SSL/certs')

以上是关于SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书)'的主要内容,如果未能解决你的问题,请参考以下文章

python使用requests时报错requests.exceptions.SSLError: HTTPSConnectionPool

Rails 3:OpenSSL::SSL::SSLError:主机名与服务器证书不匹配

用于 Elasticsearch 的 Faraday::SSLError

SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书)'

ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] 线程化时的 Gmail

pycharm fiddler requests.exceptions.SSLError