requests发送https请求时默认验证ssl证书,此时如果访问的地址ssl证书过期失效或不信任,则请求失败,为了使请求成功,可以设置verify为False,暂时不验证
可以看到解决办法,可用disable_warnings()移除警告
https://www.cnblogs.com/linmo/p/14319808.html
代码: 全选
移除ssl验证后,可以访问,但会出现一长串提示:r = requests.get(url, headers=header, verify=False)
代码: 全选
根据提示:https://urllib3.readthedocs.io/en/lates ... l-warningsInsecureRequestWarning: 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
可以看到解决办法,可用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