python requests证书问题解决


Posted in Python onSeptember 05, 2019

用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,请求即可

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
tensorflow saver 保存和恢复指定 tensor的实例讲解
Jul 26 Python
python2.7使用plotly绘制本地散点图和折线图
Apr 02 Python
在python下使用tensorflow判断是否存在文件夹的实例
Jun 10 Python
python网络爬虫 Scrapy中selenium用法详解
Sep 28 Python
基于Python和PyYAML读取yaml配置文件数据
Jan 13 Python
解决tensorflow添加ptb库的问题
Feb 10 Python
简单了解Python字典copy与赋值的区别
Sep 16 Python
Python如何急速下载第三方库详解
Nov 02 Python
Django和Ueditor自定义存储上传文件的文件名
Feb 25 Python
Pytest实现setup和teardown的详细使用详解
Apr 17 Python
python区块链持久化和命令行接口实现简版
May 25 Python
Django框架中模型的用法
Jun 10 Python
Python使用scipy模块实现一维卷积运算示例
Sep 05 #Python
Python图像处理模块ndimage用法实例分析
Sep 05 #Python
Pycharm+django2.2+python3.6+MySQL实现简单的考试报名系统
Sep 05 #Python
PyCharm搭建Spark开发环境的实现步骤
Sep 05 #Python
浅谈Python_Openpyxl使用(最全总结)
Sep 05 #Python
python实现人工智能Ai抠图功能
Sep 05 #Python
深入了解Python在HDA中的应用
Sep 05 #Python
You might like
PHP脚本的10个技巧(7)
2006/10/09 PHP
php Undefined index和Undefined variable的解决方法
2008/03/27 PHP
php入门之连接mysql数据库的一个类
2012/04/21 PHP
解析coreseek for sphinx的使用
2013/06/21 PHP
去掉destoon资讯内容页keywords关键字自带的文章标题的方法
2014/08/21 PHP
php实现的简易扫雷游戏实例
2015/07/09 PHP
php排序算法实例分析
2016/10/17 PHP
PHP实现APP微信支付的实例讲解
2018/02/10 PHP
如何用javascript判断录入的日期是否合法
2007/01/08 Javascript
可以文本显示的公告栏的js代码
2007/03/11 Javascript
JavaScript 无符号右移赋值操作
2009/04/17 Javascript
广泛收集的jQuery拖放插件集合
2012/04/09 Javascript
Jquery之Bind方法参数传递与接收的三种方法
2014/06/24 Javascript
jquery实现的蓝色二级导航条效果代码
2015/08/24 Javascript
Javascript的表单与验证-非空验证
2016/03/18 Javascript
jQuery、zepto、js常用小技巧
2017/02/12 Javascript
jquery+ajax实现省市区三级联动 (封装和不封装两种方式)
2017/05/15 jQuery
AngularJs定时器$interval 和 $timeout详解
2017/05/25 Javascript
微信小程序时间控件picker view使用详解
2018/12/28 Javascript
原生jQuery实现只显示年份下拉框
2020/12/24 jQuery
使用python 爬虫抓站的一些技巧总结
2018/01/10 Python
Python基于多线程操作数据库相关问题分析
2018/07/11 Python
python实现京东秒杀功能
2018/07/30 Python
Python抽象和自定义类定义与用法示例
2018/08/23 Python
用Python实现最速下降法求极值的方法
2019/07/10 Python
解决Python计算矩阵乘向量,矩阵乘实数的一些小错误
2019/08/26 Python
python实现按首字母分类查找功能
2019/10/31 Python
python关于变量名的基础知识点
2020/03/03 Python
使用npy转image图像并保存的实例
2020/07/01 Python
Pop In A Box英国:Funko POP搪胶公仔
2019/05/27 全球购物
食堂采购员岗位职责
2014/03/17 职场文书
党员对照检查材料思想汇报(党的群众路线)
2014/09/24 职场文书
煤矿施工安全协议书
2016/03/22 职场文书
大学社团活动总结怎么写
2019/06/21 职场文书
react国际化react-intl的使用
2021/05/06 Javascript
浅谈Python数学建模之线性规划
2021/06/23 Python