#-*-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. 01:CENTOS使用VIRTUALENV搭建独立的PYTHON环境-PYTHON虚拟环境

    1.1 安装virtualenv环境 https://www.cnblogs.com/liuyansheng/p/6141197.html 1.安装virtualenv yum install pyt ...

  2. oracle_sqlplus命令行乱码问题解决

    在linux以及unix中,sqlplus的上下左右.回退无法使用,会出现乱码情况. 而rlwrap这个软件就是用来解决这个的. 首先下载rlwrap包:https://linux.linuxidc. ...

  3. linux物理网卡检测命令mii-tool

    mii-tool    #是用于查看.管理物理的网络接口的状态,还可以配置网卡需要的协商方式. 一 ,查看网卡工作状态 mill-tool [网卡名]    #查看物理网卡连接状态 -V 显示版本信息 ...

  4. STM32之独立看门狗(IWDG)与窗口看门狗(WWDG)总结

    一.独立看门狗 STM32 的独立看门狗由内部专门的 40Khz 低速时钟驱动,即使主时钟发生故障,它也仍然有效. 看门狗的原理:单片机系统在外界的干扰下会出现程序跑飞的现象导致出现死循环,看门狗电路 ...

  5. nginx: [emerg] BIO_new_file("/etc/nginx/ssl_key/server.crt") failed (SSL: error:02001002:syste

    Centos 7.5 nginx+web集群配置https报错 报错信息: [root@lb01 conf.d]# nginx -tnginx: [emerg] BIO_new_file(" ...

  6. 装了as之后提示NO JVM installation found.....

    如图. 解决:在AS安装目录下,找到对应的程序[jdk是多少位就打开多少位的]

  7. C# asp:FileUpload上传文件使用JS实现预览效果

    js代码: <script type="text/javascript"> //下面用于图片上传预览功能 function setImagePreview() { va ...

  8. sudo用法记录

    使用root用户,visudo命令(实际是编辑/etc/sudoers文件),用法和vim一样,末行模式:wq退出,如还有提示,使用大写"Q"保存退出,小写"e" ...

  9. springBoot 全局异常捕捉

    package cn.com.cs.core.exception; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import or ...

  10. Sample Classification Code of CIFAR-10 in Torch

    Sample Classification Code of CIFAR-10 in Torch from: http://torch.ch/blog/2015/07/30/cifar.html req ...