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

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

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

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

    原文作者:jerrylearner
    原文地址: https://www.jianshu.com/p/49b74f6c6b69
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞