如何不让打印InsecureRequestWarnings警告

可以通过使用urllib3.disable_warnings()接口将发送request请求时弹出的安全类警告屏蔽,示例如下:

import requests
from requests.packages import urllib3

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

url = "https://www.booking.com/searchresults.en-gb.html"
with requests.Session() as s:
    r = s.get(url, verify=False)
    html = r.text
posted @ 2022-10-28 11:26  LuckyOven  阅读(141)  评论(0)    收藏  举报