#-*-coding:utf-8-*-
# Time:2017/9/25 20:41
# Author:YangYangJun import requests
import ssl
from requests.auth import HTTPBasicAuth def post_login(): url = "https://www.url"
values = {}
values['username'] = 'username'
values['password'] = 'password'
response = requests.post(url,values)
print response.text def get_login():
url = "https://www.url"
values = {}
values['username'] = 'username'
values['password'] = 'password'
#geturl = url + '?' + values
response = requests.get(url, values)
print response.content def post_loginHttps1(): url = "https://www.url"
values = {}
values['username'] = 'username'
values['password'] = 'password'
#临时解决https的方法1
response = requests.post(url,values,verify=False)
print response.text def post_loginHttps2():
#解决https方法2
ssl._create_default_https_context = ssl._create_unverified_context url = "https://www.url"
values = {}
values['username'] = 'username'
values['password'] = 'password'
#临时解决https的问题
response = requests.post(url,values,verify=True)
print response.text if __name__ == '__main__':
post_login()
#get_login()
post_loginHttps1()
# post_loginHttps2() #出现下面错误的原因主要是因为打开了fiddler,关闭fiddler即可。 # raise SSLError(e, request=request)
# requests.exceptions.SSLError: HTTPSConnectionPool(host='www.yiyao.cc', port=443): Max retries exceeded with url: /user/loginWeb (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661)'),))
#

知乎:https://www.zhihu.com/question/40025043  有介绍解决的办法,如上代码,方法一:关闭校验,方法二:导入其他库,定义ssl._create_default_https_context = ssl._create_unverified_context。

其实根本原因是打开了fiddler,关闭即可,如果不关闭,方法一也可以,方法二还是不好使。故执行时要关闭 fiddler是最保险的。

同时如果打开了fiddler,访问https网站时,页面可能会提示不信任无法加载的提示,这是fiddler证书不受信任的问题。解决办法如下。

然后选择export root .....

然后桌面会生成一个

然后通过 不同浏览器的证书导入即可

选择证书执行导入。

Python - requests https请求的坑的更多相关文章

  1. python爬虫 - python requests网络请求简洁之道

    http://blog.csdn.net/pipisorry/article/details/48086195 requests简介 requests是一个很实用的Python HTTP客户端库,编写 ...

  2. python requests http请求

    导入模块 import requests import json header = {'Content-Type': 'application/json'} data = {"} data ...

  3. python requests发起请求,报“Max retries exceeded with url”

    需要高频率重复调用一个接口,偶尔会出现"Max retries exceeded with url" 在使用requests多次访问同一个ip时,尤其是在高频率访问下,http连接 ...

  4. python requests https 访问出错

    错误提示: /usr/local/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:100: InsecurePla ...

  5. Python - requests发送请求报错:UnicodeEncodeError: 'latin-1' codec can't encode characters in position 13-14: 小明 is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.

    背景 在做接口自动化的时候,Excel作为数据驱动,里面存了中文,通过第三方库读取中文当请求参数传入 requests.post() 里面,就会报错 UnicodeEncodeError: 'lati ...

  6. python + requests发起请求,接口返回400,报错“Unexpected character encountered while parsing value: G. Path”

    完整报错信息如下: {'errors': {'': ["Unexpected character encountered while parsing value: G. Path '', l ...

  7. [错误记录]python requests库 Response 判断坑

    在requests访问之后, 我直接判断resp的值, 如下: if resp: do something 发现当Response 为500的时候没有进入if分支, 检查源码,发现Response重写 ...

  8. Python+requests维持会话

    Python+requests维持会话 一.使用Python+requests发送请求,为什么要维持会话? 我们是通过http协议来访问web网页的,而http协议是无法维持会话之间的状态.比如说我们 ...

  9. Python常见问题 - python3 使用requests发送HTTPS请求报certificate verify failed 错误

    当你使用 requests 发送HTTPS请求时 requests.get(url, parmas=parmas, headers=header, cookies=cookie) 出现了以下错误 HT ...

随机推荐

  1. Systen,IO

    private void CreateHtml(string sPath, string txt) { string currPath = @"C:\MyCodeHelper" + ...

  2. 牛客网数据库SQL实战(16-20)

    16.统计出当前各个title类型对应的员工当前薪水对应的平均工资.结果给出title以及平均工资avg.CREATE TABLE `salaries` (`emp_no` int(11) NOT N ...

  3. 【转】java提高篇之理解java的三大特性——多态

    面向对象编程有三大特性:封装.继承.多态. 封装隐藏了类的内部实现机制,可以在不影响使用的情况下改变类的内部结构,同时也保护了数据.对外界而已它的内部细节是隐藏的,暴露给外界的只是它的访问方法. 继承 ...

  4. CentOS6.8下安装Redis

    1.由于Redis是使用C语言开发的,安装时需要对Redis的源码进行编译,编译依赖gcc环境,如果没有gcc,需要先安装gcc: yum install gcc-c++ 2.安装完成后,进入Redi ...

  5. innerHTML和 innerText的区别

    共同点:innerHTML和innerText都会把元素内内容替换掉.不同点:1,innerHTML: 也就是从对象的起始位置到终止位置的全部内容,包括Html标签. 上例中的test.innerHT ...

  6. PyCharm史上最强攻略

    Ctrl + D 复制选定的区域或行 Ctrl + Y 删除选定的行 Ctrl + Alt + L 代码格式化 Ctrl + Alt + O 优化导入(去掉用不到的包导入) Ctrl + 鼠标 简介/ ...

  7. SpringBoot Mybatis 分页插件PageHelper

    添加maven配置: <!-- 分布插件 --> <dependency> <groupId>com.github.pagehelper</groupId&g ...

  8. oracle单行函数 之 字符函数

    Upper(字符串 / 列):将输入的字符串变成大写 Lower(字符串 / 列):将输入的字符串变成小写 Initcap(字符串 / 列):开头首字母大写 Length(字符串 / 列):字符串长度 ...

  9. (转) Supercharging Style Transfer

      Supercharging Style Transfer Wednesday, October 26, 2016 Posted by Vincent Dumoulin*, Jonathon Shl ...

  10. CAS Client集群环境的Session问题及解决方案介绍,下篇介绍作者本人项目中的解决方案代码

    CAS Client集群环境的Session问题及解决方案  程序猿讲故事  2016-05-20  原文 [原创申明:文章为原创,欢迎非盈利性转载,但转载必须注明来源] 之前写过一篇文章,介绍单点登 ...