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 ...
随机推荐
- CSM与UEFI
最近公司产品部购置一批新电脑,但是预装的win10不能保证兼容老平台软件,于是安装win7系统的任务就落到了我的手中. 观察参数,是8代的U,产品说运维说无能为力,装不了win7.我在网上搜了一下,是 ...
- linux 函数库使用
程序函数库可分为3种类型:静态函 数库(static libraries).共享函数库(shared libraries)和动态加载函数库(dynamically loaded libraries) ...
- 写给大忙人的spring cloud 1.x学习指南
这几天抽空搞了下spring cloud 1.x(2.0目前应该来说还不成熟),因为之前项目中使用dubbo以及自研的rpc框架,所以总体下来还是比较顺利,加上spring boot,不算笔记整理,三 ...
- python简说(六)判断
非空即真,非0即真True '1' [1] {k-v}False '' None [] {}
- opencv学习之路(6)、鼠标截图,滑动条播放视频
一.鼠标截图 #include<opencv2/opencv.hpp> #include<iostream> using namespace cv; using namespa ...
- Codeforces 700B Connecting Universities - 贪心
Treeland is a country in which there are n towns connected by n - 1 two-way road such that it's poss ...
- 【Python58--正则2】
一.字符匹配 1.元字符:完整列表:. ^ $ * + ? { } [ ] \ | ( ) 元字符 描述 .点 匹配除换行符外任意一个字符 x|y 匹配 x 或 ...
- ./configure: error: C compiler cc is not found
没有安装gcc 在安装nginx之前先安装依赖软件 yum install -y gcc gcc-c++ autoconf pcre pcre-devel make automake wget htt ...
- 测试浏览器对HTML5标签的支持
使用相应的浏览器打开链接 https://html5test.com/即可在该页面查看到测试结果.
- topcoder srm 480 div1
problem1 link 直接模拟即可. problem2 link 首先,网关一定是安装在client与server之间的链路上.而不会安装在client与client之间的链路上.对于一条路径c ...