## ssl verification error in python [python ssl 憑證錯誤] 在Python中,使用requests等套件進行爬蟲時如果遇到ssl verification error ` (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1016)')))` 此時可以嘗試透過更新certifi或是自行安裝ca檔來進行排除 ### 1. 更新certifi `pip install --upgrade certifi urllib3` ### 2. 自行安裝 如果狀況未能排除,則需要透過手動把該網頁憑證加入本地憑證目錄中 1. 找到憑證位置 ```python! import certifi print(certifi.where()) ``` 2. 下載網頁憑證(先到目標網頁利用F12、隱私與安全性、檢視憑證) ![image](https://hackmd.io/_uploads/H1_GE5J4xx.png) 知道憑證頒發機構後,至機構網址進行下載 ![image](https://hackmd.io/_uploads/r12PVcJEee.png) 這邊以TWCA為例(不同發行機構要找到目標檔案的容易度不同:cry:),到ssl 憑證搜尋的地方尋找,並輸入網址(不要https、不要\後的文字)(root only) ![image](https://hackmd.io/_uploads/ryS6E5y4gg.png) 選擇憑證鍊 ![image](https://hackmd.io/_uploads/rJ5DSqJ4gg.png) 下載後檔案如下: ![image](https://hackmd.io/_uploads/HJq9ScyVle.png) 3. 以文字編輯器開啟uca.cer (沒用文字編輯器會變成請問要不要安裝憑證的畫面) ![image](https://hackmd.io/_uploads/Sy5J85y4ll.png) 4. 以文字檔開啟`certifi.where()`,將憑證貼至檔案底部! ## 就完成了!