欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

使用requests时报错:requests.exceptions.SSLError: HTTPSConnectionPool

程序员文章站 2022-05-13 12:48:22
示例代码:import requestsr = requests.get('https://www.12306.cn')print(r.status_code)报错:requests.exceptions.SSLError: HTTPSConnectionPool(host='某某某网站', port=443): Max retries exceeded with url: /login/ (Caused by SSLError(SSLError("bad handshake: Error([(...

示例代码:

import requests
r = requests.get('https://www.12306.cn')
print(r.status_code)

报错:

requests.exceptions.SSLError: HTTPSConnectionPool(host='某某某网站', port=443): Max retries exceeded with url: /login/ (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed

这里是由于这个网页的证书没有被官方CA机构信任,所以这里会出现证书验证的错误。

解决方案:

增加verify参数

import requests
r = requests.get('https://www.12306.cn', verify=False)
print(r.status_code)

以上参考:https://blog.csdn.net/weixin_44385104/article/details/94750593

如果依然无法解决,可能是网络问题,如重启网络,关闭代理等

本文地址:https://blog.csdn.net/LMFranK/article/details/107475246

相关标签: Problem python