python requests请求SSL证书问题
作者:互联网
requests发送https请求时默认验证ssl证书,此时如果访问的地址ssl证书过期失效或不信任,造成请求失败
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/latest/advanced-usage.html#ssl-warnings
可以看到解决办法,可用disable_warnings()移除警告
#在requests请求前添加 requests.packages.urllib3.disable_warnings()
完整代码:
import requests requests.packages.urllib3.disable_warnings() r = requests.get(url, headers=header, verify=False)
End
标签:请求,ssl,warnings,python,urllib3,SSL,https,requests 来源: https://blog.51cto.com/u_13771903/2724961