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

如果是兩個以上的域名以此類推,貢獻給大家,希望對遇到同樣問題的同學有所幫助。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章