pip安裝第三方包報錯:There was a problem confirming the ssl certificate


錯誤提示

突然使用python直接使用pip install xx時,出現報錯:

Could not fetch URL https://pypi.org/simple/pymysql/: There was a problem confirming the ssl certificate: HTTPSConnectio
nPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pymysql/ (Caused by SSLError(SSLError(1, '[SSL:
CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)) - skipping

報錯內容如下:

PS C:\Users\yinha> pip install pymysql
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)': /simple/pymysql/ WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)': /simple/pymysql/ WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)': /simple/pymysql/ WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)': /simple/pymysql/ WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)': /simple/pymysql/ Could not fetch URL https://pypi.org/simple/pymysql/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pymysql/ (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)) - skipping ERROR: Could not find a version that satisfies the requirement pymysql (from versions: none) ERROR: No matching distribution found for pymysql

解決過程

一開始以為是ide環境出了問題,后來在終端,在虛擬環境測試都會報錯。

1. 重裝python  無效

2.重裝pip    無效

 

python -m pip uninstall pip

C:\Python36\Scripts>easy_install.exe -i http://mirrors.aliyun.com/pypi/simple/ pip

 

 

3.添加--trusted-host  有效

但是每次安裝增加此參數,比較麻煩

pip install pymysql -i http://pypi.tuna.tsinghua.edu.cn/simple/ --trusted-host pypi.tuna.tsinghua.edu.cn

 

4.創建pip配置pip.ini。  有效

(1)在系統目錄C:\Users\用戶\AppData\Roaming新建pip文件夾;

(2)在pip文件夾下新建pip.ini文件,並寫入如下配置:

[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host = mirrors.aliyun.com

 5.關閉Fiddler

看到這里真的是崩潰,開啟它之后運行python會自動改變端口,造成ssl錯誤。

不多解釋了,關掉就好,說多了都是淚。

 

順便說一下:開啟Fiddler后,對requests模塊也會產生ssl認證的報錯。

之前沒發現這個原因時,就靠如下方法對付:

# 忽略警告
requests.packages.urllib3.disable_warnings()
#取消認證
requests.get(url=url,cookies=cookies,verify=False)

 

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM