python requests 请求报错 unable to get local issuer certificate (_ssl.c:1051) 解决办法
作者:互联网
文章目录
报错内容
HTTPSConnectionPool(host=‘cucp.cuc.edu.cn’, port=443): Max retries exceeded with url: /_upload/article/images/54/fa/6ab15fa9490a96389065d17f7d9f/bfe4ef7b-b6f1-4397-aa1d-22ac063377a1.png (Caused by SSLError(SSLCertVerificationError(1, ‘[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1051)’)))
原因
使用requests模块请求一个证书无效的网站
参考文档:http://cn.python-requests.org/zh_CN/latest/
解决办法
将 requests 请求的参数 verify 设置为 False
res = requests.get('https://www.csdn.net/', verify=False)
print(res.status_code)
ps:到此为止就可以发送请求了,不过还会有一个类似于这样的警告信息
InsecureRequestWarning: Unverified HTTPS request is being made to host ‘cucp.cuc.edu.cn’. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
InsecureRequestWarning,
如果有强迫症的话,可以通过这两行代码忽略掉警告
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
标签:1051,certificate,get,ssl,报错,InsecureRequestWarning,requests 来源: https://blog.csdn.net/weixin_43721000/article/details/122107484