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