python requests证书问题解决
作者:我曾把春天丢了 时间:2023-10-12 22:58:12
用requests包请求https的网站时,我们偶尔会遇到证书问题。也就是常见的SSLerror,遇到这种问题莫慌莫慌。
这里没有找到合适的网站去报SSL证书的错误,所以就假装请求了一个https的网站,然后给报了SSLerror了,然后下面是解决方法
可以直接关闭验证ssl证书
import requests
'''
:param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.
:param verify: (optional) Either a boolean, in which case it controls whether we verify
the server's TLS certificate, or a string, in which case it must be a path
to a CA bundle to use. Defaults to ``True``.
'''
r = requests.get('https://kyfw.12306.cn',verify=False)
print(r.text)
这种方式直接在函数里面加如verify改变Ture或者False即可,因为post与get调用的都为request()函数,所以get与post都一样。
如果这种方式奏效就用这种方式,如果不奏效就用下面的一种
import requests
'''
:param verify: (optional) Either a boolean, in which case it controls whether we verify
the server's TLS certificate, or a string, in which case it must be a path
to a CA bundle to use. Defaults to ``True``.
'''
## 证书路径
cert = '../cert/test.pem'
r = requests.get('https://kyfw.12306.cn',verify=cert)
print(r.text)
就用这种,直接把证书的路径丢给verify,请求即可
来源:https://www.cnblogs.com/dflblog/p/11465044.html
标签:python,requests,证书,问题
0
投稿
猜你喜欢
Python confluent kafka客户端配置kerberos认证流程详解
2021-02-25 10:47:31
MySQL查询优化:LIMIT 1避免全表扫描提高查询效率
2024-01-29 08:33:13
asp.net FindControl方法误区和解析
2024-06-05 09:28:08
rollup3.x+vue2打包组件的实现
2024-05-22 10:43:40
Python用GET方法上传文件
2022-08-03 01:13:59
Python格式化输出--%s,%d,%f的代码解析
2022-10-31 06:26:44
查看当前mysql使用频繁的sql语句(详解)
2024-01-18 19:58:47
在ASP.NET 2.0中操作数据之十九:给编辑和新增界面增加验证控件
2024-05-09 09:04:01
VSCode下配置python调试运行环境的方法
2023-03-27 10:15:40
在sql中实现取一行最大值或者最小值
2024-01-24 21:34:28
PHP数组交集的优化代码分析
2023-09-29 21:58:59
在matplotlib的图中设置中文标签的方法
2023-10-10 07:17:53
Pandas处理DataFrame稀疏数据及维度不匹配数据分析详解
2023-08-20 02:44:38
python imutils包基本概念及使用
2023-10-20 21:38:09
讲解数据库管理系统必须提供的基本服务
2009-01-04 14:33:00
基于Python实现视频的人脸融合功能
2021-07-12 06:41:59
python实现kNN算法
2023-01-24 13:58:06
盗亦有道 Web2.0网站优秀模仿者逐个数
2007-09-11 19:46:00
Python OpenCV图像处理之图像滤波特效详解
2021-06-07 04:36:02
python 循环遍历字典元素的简单方法
2023-12-15 08:06:15