1、python接口测试requests
import requests
import json
r=requests.get('http://www.baidu.com') #get 请求方式
r=requests.post('http://www.baidu.com') #post 请求方式
----------------------------------------------
r=requests.get('http://www.baidu.com',params={'1':'a','2':'b'}) #get 带参数请求方式
两种post方法:
r=requests.post('http://www.baidu.com',data=json.dumps({'1':'a','2':'b'})) #post 带参数请求方式
r=requests.post('http://www.baidu.com',json={'1':'a','2':'b'}) #post 带参数请求方式
----------------------------------------------
r.url #查看请求url
r.text #查看响应信息,可以切片使用
r.text[8:15] #查看响应信息的第8到14个字符
r.headers #查看响应头
r.content #以二进制查看响应信息
r.encoding #查看响应信息编码格式
r.status_code #查看响应状态码
r.json() #如果响应体返回的是json格式,通过这个方法可以自动转化成json格式
r.raise_for_status() #失败请求(非200)抛出异常
----------------------------------------------------------------
#get方法带参数的四种用法
parameter={'user_name':'liu','passwd':'123456'}
r=requests.get('http://www.baidu.com',parameter)
或
r=requests.get('http://www.baidu.com',params={'user_name':'liu','passwd':'123456'}) #参数params不能自定义写成其他的
或
parameter={'user_name':'liu','passwd':'123456'}
rb=requests.get('http://www.baidu.com',params=parameter)
或
r=requests.get('http://www.baidu.com',{'user_name':'liu','passwd':'123456'})
-----------------------------------------------------------------------------------
ur=requests.get('http://www.baidu.com',{'user_name':'liu','passwd':'123456'})
示例:
r=requests.post('http://IP:ports/API/api',json={'method':'user.login','appkey':'KEY','sig':'6c780877e645f5eff0f5e30e0193d49ee0c7ddcf','username':'testing','password':'WQ123456wq'})
注释:
1、url为http://ip:ports/api包名/api
2、method的values值为接口名称
1、python接口测试requests的更多相关文章
- python的requests用法详解
Requests是一个Python语言写的http相关设置或者请求的一个库 安装:pip install Requests或者pip3 install requests 使用的时候要import re ...
- 【转】使用Python的Requests库进行web接口测试
原文地址:使用Python的Requests库进行web接口测试 1.Requests简介 Requests 是使用 Apache2 Licensed 许可证的 HTTP 库.用 Python 编写, ...
- 对比3种接口测试的工具:jmeter+ant;postman;python的requests+unittest或requests+excel
这篇随笔主要是对比下笔者接触过的3种接口测试工具,从实际使用的角度来分析下3种工具各自的特点 分别为:jmeter.postman.python的requests+unittest或requests+ ...
- Python接口测试-使用requests模块发送GET请求
本篇主要记录下使用python的requests模块发送GET请求的实现代码. 向服务器发送get请求:无参数时:r = requests.get(url)带params时:r = requests. ...
- Python接口测试-使用requests模块发送post请求
本篇主要记录下使用python的requests模块发送post请求的实现代码. #coding=utf-8 import unittest import requests class PostTes ...
- Python 接口测试(十)
这里对接口测试9 进行优化升级,前端进行重构后的代码,源码已经开源 经过将近一个月的编写 , TIAPTest 接口测试平台 , 已经部署到服务器,开始运行了. http://60.205.187.1 ...
- 关于Python ,requests的小技巧
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/xie_0723/article/details/52790786 关于 Python Request ...
- Python接口测试实战4(下) - 框架完善:用例基类,用例标签,重新运行上次失败用例
如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...
- Python接口测试实战5(下) - RESTful、Web Service及Mock Server
如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...
随机推荐
- rqalpha探究 1 setup.py
rqalpha是难得几个好的做量化交易的开源项目,不过由于自己python用的实在不多,看起来还是觉得很复杂. 因此准备抽取出框架,从最简单的搭建. 思路 从setup着手,看一下如何建立一个发布工程 ...
- c#扩展函数
分页 public static class IEnumerableExt { public static (IEnumerable<T> dataAfterPaging, Pageinf ...
- Java 8 并发性基础
https://www.ibm.com/developerworks/cn/java/j-jvmc2/index.html http://www.nurkiewicz.com/2013/05/java ...
- RabbitMQ随笔
不管是官方还是能搜到的文章,使用MQ的基本思路都是这样: static void Main(string[] args) { //通过工厂建立连接 using (IConnection connect ...
- Android手机用KSWEB搭建Web服务器成功安装WordPress
之前部落分享的几个免费Web服务器软件都是用来安装在本地电脑上,搭建Apache.PhpMyAdmin.MySQL等网站运行环境,然后我们就可以在电脑上测试运行Wordpress.Discuz! 论坛 ...
- 【CF944G】Coins Exhibition DP+队列
[CF944G]Coins Exhibition 题意:Jack去年参加了一个珍稀硬币的展览会.Jack记得一共有 $k$ 枚硬币,这些硬币排成一行,从左到右标号为 $1$ 到 $k$ ,每枚硬币是正 ...
- B - Image Perimeters
Technicians in a pathology lab analyze digitized images of slides. Objects on a slide are selected f ...
- go 的正则表达式
go 操作字符串.由于 go 中的字符串不是对象,所以没有直接操作字符串的相关方法.要操作字符串可以使用 strings 包或者 regexp 包处理. 一.简要介绍一下,strings 包 (str ...
- 微软VBS生成Excel内容和图表示例
<HTML> <BODY> <INPUT id=button1 name=button1 type=button value=Button> <SCRIPT ...
- 怎么关闭win10防火墙
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows Defender" /v "Disable ...