requests - ssl认证
有些网站由于证书不受信任(由于不是证书机构发布的,就不被信任),所以打开浏览器则会出现如下情况,需要点击高级,然后继续。这个如何用requests实现,如下


import requests response = requests.get('https://192.168.2.1/',verify=False) print(response.status_code)
结果为:
D:\Program Files\python\Python38\lib\site-packages\urllib3\connectionpool.py:1013: InsecureRequestWarning: Unverified HTTPS request is being made to host '192.168.2.1'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
warnings.warn(
D:\Program Files\python\Python38\lib\site-packages\urllib3\connectionpool.py:1013: InsecureRequestWarning: Unverified HTTPS request is being made to host '192.168.2.1'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
warnings.warn(
200
上面会出现告警提示(红字所示),如何去掉告警,加上告警抑制即可
import requests from requests.packages import urllib3 urllib3.disable_warnings() response = requests.get('https://192.168.2.1/',verify=False) print(response.status_code)
结果为:
200

浙公网安备 33010602011771号