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的更多相关文章

  1. python的requests用法详解

    Requests是一个Python语言写的http相关设置或者请求的一个库 安装:pip install Requests或者pip3 install requests 使用的时候要import re ...

  2. 【转】使用Python的Requests库进行web接口测试

    原文地址:使用Python的Requests库进行web接口测试 1.Requests简介 Requests 是使用 Apache2 Licensed 许可证的 HTTP 库.用 Python 编写, ...

  3. 对比3种接口测试的工具:jmeter+ant;postman;python的requests+unittest或requests+excel

    这篇随笔主要是对比下笔者接触过的3种接口测试工具,从实际使用的角度来分析下3种工具各自的特点 分别为:jmeter.postman.python的requests+unittest或requests+ ...

  4. Python接口测试-使用requests模块发送GET请求

    本篇主要记录下使用python的requests模块发送GET请求的实现代码. 向服务器发送get请求:无参数时:r = requests.get(url)带params时:r = requests. ...

  5. Python接口测试-使用requests模块发送post请求

    本篇主要记录下使用python的requests模块发送post请求的实现代码. #coding=utf-8 import unittest import requests class PostTes ...

  6. Python 接口测试(十)

    这里对接口测试9 进行优化升级,前端进行重构后的代码,源码已经开源 经过将近一个月的编写 , TIAPTest 接口测试平台 , 已经部署到服务器,开始运行了. http://60.205.187.1 ...

  7. 关于Python ,requests的小技巧

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/xie_0723/article/details/52790786 关于 Python Request ...

  8. Python接口测试实战4(下) - 框架完善:用例基类,用例标签,重新运行上次失败用例

    如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...

  9. Python接口测试实战5(下) - RESTful、Web Service及Mock Server

    如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...

随机推荐

  1. hdoj:2047

    #include <iostream> using namespace std; ] = { , , }; // O,E 组成长度为n的数量 long long fib(int n) { ...

  2. No service of type Factory<LoggingManagerInternal> available in ProjectScopeService

    导入GitHub上下载的项目时报错 No service of type Factory<LoggingManagerInternal> available in ProjectScope ...

  3. 响应式编程笔记三:一个简单的HTTP服务器

    # 响应式编程笔记三:一个简单的HTTP服务器 本文我们将继续前面的学习,但将更多的注意力放在用例和编写实际能用的代码上面,而非基本的APIs学习. 我们会看到Reactive是一个有用的抽象 - 对 ...

  4. Secure backup

    Secure backup 安全备份软件 安全备份软件致力于提供一款开源免费的安全云备份软件,支持文件管理,文件自动同步到云盘,增量备份等功能. 目前正在开发过程中...

  5. js实现滑动的弹性导航

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  6. last

    last reboot 显示系统最后重启的历史记录 last -w 显示自系统启动以来,所有登录的用户(全名)

  7. nohup 和 &的含义

    https://www.cnblogs.com/jinxiao-pu/p/9131057.html

  8. OSG模拟鼠标事件影响操纵器

    viewer->getEventQueue()->mouseButtonPress(0,0,1); viewer->getEventQueue()->mouseMotion(1 ...

  9. 一款Redis客户端,可以作为Redis Desktop manager的有效补充或替代

    一.由来 对于redis客户端,我和大多数人一样,都是用Redis Desktop Manager. 但我发现个问题,我的版本是0.9.1.771. 我这个版本有个问题,就是如果value太长的话,不 ...

  10. Linux中 SonarQube代码质量管理平台安装

    SonarQube是管理代码质量一个开源平台,可以快速的定位代码中潜在的或者明显的错误. SonarQube安装 1.环境准备 (1)sonarQube 下载地址https://www.sonarqu ...