Python - requests https请求的坑

#-*-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请求的坑的更多相关文章
- python爬虫 - python requests网络请求简洁之道
http://blog.csdn.net/pipisorry/article/details/48086195 requests简介 requests是一个很实用的Python HTTP客户端库,编写 ...
- python requests http请求
导入模块 import requests import json header = {'Content-Type': 'application/json'} data = {"} data ...
- python requests发起请求,报“Max retries exceeded with url”
需要高频率重复调用一个接口,偶尔会出现"Max retries exceeded with url" 在使用requests多次访问同一个ip时,尤其是在高频率访问下,http连接 ...
- python requests https 访问出错
错误提示: /usr/local/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:100: InsecurePla ...
- 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 ...
- python + requests发起请求,接口返回400,报错“Unexpected character encountered while parsing value: G. Path”
完整报错信息如下: {'errors': {'': ["Unexpected character encountered while parsing value: G. Path '', l ...
- [错误记录]python requests库 Response 判断坑
在requests访问之后, 我直接判断resp的值, 如下: if resp: do something 发现当Response 为500的时候没有进入if分支, 检查源码,发现Response重写 ...
- Python+requests维持会话
Python+requests维持会话 一.使用Python+requests发送请求,为什么要维持会话? 我们是通过http协议来访问web网页的,而http协议是无法维持会话之间的状态.比如说我们 ...
- Python常见问题 - python3 使用requests发送HTTPS请求报certificate verify failed 错误
当你使用 requests 发送HTTPS请求时 requests.get(url, parmas=parmas, headers=header, cookies=cookie) 出现了以下错误 HT ...
随机推荐
- Python3 Pandas的DataFrame数据的增、删、改、查
Python3 Pandas的DataFrame数据的增.删.改.查 一.DataFrame数据准备 增.删.改.查的方法有很多很多种,这里只展示出常用的几种. 参数inplace默认为False,只 ...
- python3 获取cookie解决方案
python3 获取cookie解决方案 方案一: 利用selenium+phantomjs无界面浏览器的形式访问网站,再获取cookie值: from selenium import webdriv ...
- sql xml 入门 (二)
DECLARE @myDoc xml --http://www.paymob.cn --话费充值api,充值api,话费充值接口,手机话费充值,车贝手机,贝萌手机,移动话费充值,联通话费充值,电信话费 ...
- Codeforces 235C Cyclical Quest - 后缀自动机
Some days ago, WJMZBMR learned how to answer the query "how many times does a string x occur in ...
- 转载:索引与分片 plus
[Python笔记]序列(一)索引.分片 Python包含6种内建序列:列表.元组.字符串.Unicode字符串.buffer对象.xrange对象.这些序列支持通用的操作: 索引 索引是从0开始 ...
- PowerDesigner 学习:十大模型及五大分类
个人认为PowerDesigner 最大的特点和优势就是1)提供了一整套的解决方案,面向了不同的人员提供不同的模型工具,比如有针对企业架构师的模型,有针对需求分析师的模型,有针对系统分析师和软件架构师 ...
- topcoder srm 410 div1
problem1 link 不包含$gridConnections$ 的联通块一定是连在所有包含$gridConnections$的联通块中最大的那一块上. import java.util.*; i ...
- SVM学习笔记2-拉格朗日对偶
下面我们抛开1中的问题.介绍拉格朗日对偶.这一篇中的东西都是一些结论,没有证明. 假设我们有这样的问题:$min_{w}$ $f(w)$,使得满足:(1)$g_{i}(w)\leq 0,1\leq i ...
- [翻译]使用VH和VW实现真正的流体排版
前言 不像响应式布局,通过media query,设置几个变化点来适配,流体排版通过调整大小,适配所有设备宽度.这个方法可以使我们开发的网页,在几乎所有屏幕尺寸上都可以使用.但出于一些原因,它的使用率 ...
- shell脚本中如何实现scp传输?
示例脚本如下: #! /bin/sh expect -c " spawn scp -r /home/jello/jello.txt jello@110.110.110.110:/home/j ...