python requests 请求报错 unable to get local issuer certificate (_ssl.c:1051) 解决办法
2021/12/23 17:13:51
本文主要是介绍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)
这篇关于python requests 请求报错 unable to get local issuer certificate (_ssl.c:1051) 解决办法的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python