PIP安装第三方库报错SSL: CERTIFICATE_VERIFY_FAILED

本文介绍了解决在使用pip安装第三方库时遇到的SSL证书验证失败问题的方法。通过添加--trusted-host参数指定受信任的主机,成功解决了因证书验证失败导致的安装失败问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天在安装一个第三方库时报如下错误

pip install --upgrade baostock

Could not fetch URL https://pypi.org/simple/baostock/: There was a problem confi

rming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max r

etries exceeded with url: /simple/baostock/ (Caused by SSLError(SSLCertVerificat

ionError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self si

gned certificate in certificate chain (_ssl.c:1045)'))) - skipping

当前python版本是3.7,网上查找说是python高版本需要验证ssl,可以添加--trusted-host domain来解决,于是赶紧尝试一下

pip install --trusted-host pypi.org --upgrade baostock

又报如下错误

Could not install packages due to an EnvironmentError: HTTPSConnectionPool(host=

'files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/57

/f8/e909079851f6ea6685bb63ea143c66a0f4141fc3ce17e728ec908819ed54/baostock-0.8.5-

py3-none-any.whl (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFIC

ATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certifi

cate chain (_ssl.c:1045)')))

原来是另一个域名files.pythonhosted.org也是https的,也需要指定为trusted-host才可以,问题是同时指定两个域名为trusted-host该怎么写呢?网上找了半天没找到,经过自己一番摸索,发现如下的写法可以

pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org  --upgrade  baostock

如果是两个以上的域名以此类推,贡献给大家,希望对遇到同样问题的同学有所帮助。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值