問題:
使用Python3 requests發送HTTPS請求,已經關閉認證(verify=False)情況下,控制台會輸出以下錯誤:
InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
解決方法:
在代碼中添加以下代碼即可解決:
1 import urllib3 2 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
Python2添加如下代碼即可解決:
1 from requests.packages.urllib3.exceptions import InsecureRequestWarning 2 # 禁用安全請求警告 3 requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
requests.exceptions.SSLError: HTTPSConnectionPool(host='XXX', port=443)
解決方法如下:
1、先檢查是否已安裝requests的依賴安裝包:
pip install cryptography
pip install pyOpenSSL
pip install certifi
2、如果已經安裝依賴安裝包,還會報錯,則在請求后面加上verify=False就可以