requests.exceptions.SSLError報錯


requests.exceptions.SSLError: HTTPSConnectionPool(host='www.baidu.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)'),))  

 
錯誤提示就是上面這樣的。首先我找了很多的資料,有很多人說關閉證書驗證(verify=False))可以解決這個問題或者說是在進行GET時,指定SSL證書.
response = requests.get('http://www.baidu.com/', headers = header, verify=False)  
但我用以上兩種方法都沒有完美解決此問題,而且有些還有后續錯誤比如InsecureRequestWarning

 

正確的做法參考文檔資料

https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings

https://urllib3.readthedocs.io/en/latest/user-guide.html#ssl

參考博客:http://blog.csdn.net/zahuopuboss/article/details/52964809

 

只要安裝一下幾個requests依賴包就可以解決此問題

 

pip install cryptography 

pip install pyOpenSSL

pip install certifi

 

原文轉至博客:https://blog.csdn.net/qq_31077649/article/details/79013199

 


免責聲明!

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



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