分页: 1 / 1

python requests请求SSL证书问题

帖子发表于 :周二 4月 27, 2021 12:08 am
adm1n
requests发送https请求时默认验证ssl证书,此时如果访问的地址ssl证书过期失效或不信任,则请求失败,为了使请求成功,可以设置verify为False,暂时不验证
代码: 全选r = requests.get(url, headers=header, verify=False)
移除ssl验证后,可以访问,但会出现一长串提示:
代码: 全选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 InsecureRequestWarning
根据提示:https://urllib3.readthedocs.io/en/lates ... l-warnings
可以看到解决办法,可用disable_warnings()移除警告
代码: 全选#在requests请求前添加 requests.packages.urllib3.disable_warnings()
完整代码:
代码: 全选import requests requests.packages.urllib3.disable_warnings() r = requests.get(url, headers=header, verify=False)
文章来源:
https://www.cnblogs.com/linmo/p/14319808.html