python2/3 發送https請求時,告警關閉方法


問題:

使用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
2
import  urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
 
        

 Python2添加如下代碼即可解決:

1
2
3
from  requests.packages.urllib3.exceptions  import  InsecureRequestWarning
# 禁用安全請求警告
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)


免責聲明!

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



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