问题描述:
在requests做请求的时候,为了避免ssl认证,可以将verify=False,但是这么设置会带来一个问题,日志中会有大量的warning信息, 如下面:
D:\Program Files\Python\lib\site-packages\urllib3\connectionpool.py:1045: InsecureRequestWarning: Unverified HTTPS request is being made to host '127.0.0.1'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings warnings.warn(
解决办法:
-
原因分析:如果想把这些报错信息去掉,只需要在请求的地方加上requests.packages.urllib3.disable_warnings()!
-
解决办法:如果想把这些报错信息去掉,只需要在请求的地方加上requests.packages.urllib3.disable_warnings():
session = requests.Session() session.keep_alive = False requests.adapters.DEFAULT_RETRIES = 5 requests.packages.urllib3.disable_warnings() response = requests.get(url, params=params, headers=headers, verify=False)
再次执行就不会有报警告了。