用Python的requests库作接口测试——上传文件
来源:互联网 发布:ae软件破解版 编辑:程序博客网 时间:2024/06/01 09:52
POST一个多部分编码(Multipart-Encoded)的文件
Requests使得上传多部分编码文件变得很简单:>>> url = 'http://httpbin.org/post'>>> files = {'file': open('report.xls', 'rb')}>>> r = requests.post(url, files=files)>>> r.text{ ... "files": { "file": "<censored...binary...data>" }, ...}你可以显式地设置文件名,文件类型和请求头:
>>> url = 'http://httpbin.org/post'>>> files = {'file': ('report.xls', open('report.xls', 'rb'), 'application/vnd.ms-excel', {'Expires': '0'})}>>> r = requests.post(url, files=files)>>> r.text{ ... "files": { "file": "<censored...binary...data>" }, ...}
流式上传
Requests支持流式上传,这允许你发送大的数据流或文件而无需先把它们读入内存。要使用流式上传,仅需为你的请求体提供一个类文件对象即可:
with open('massive-body') as f: requests.post('http://some.url/streamed', data=f)
0 0
- 用Python的requests库作接口测试——上传文件
- 用Python的requests库作接口测试——对响应进行迭代
- 使用Python的requests库作接口测试——对HPPT动词的支持
- 使用Python的requests库作接口测试——请求对象与响应对象
- 使用Python的requests库作接口测试——响应头中的链接字段
- 使用Python的requests库作接口测试——身份认证
- 使用Python的requests库作接口测试——响应结果处理
- 使用Python的requests库进行接口测试——session对象的妙用
- 使用Python的Requests库进行web接口测试
- 使用Python的Requests库进行web接口测试
- python+requests+excel 接口测试
- python+requests实现接口测试
- python+requests实现接口测试
- python requests做接口测试对json的处理
- Python-Requests库进行接口测试(一)
- 接口测试框架(基于json格式、http请求)基于Excel文件管理测试用例(python+requests)
- python的requests发送/上传多个文件
- Python + Requests + Unittest接口自动化测试
- springmvc后台数据验证
- 【HNOI2004】【BZOJ1213】高精度开根
- 数据库查询显示问题
- 安卓文件安全删除问题 --- java.io.IOException: open failed: EBUSY (Device or resource busy) (System.err)
- SpringMVC源码剖析(二)- DispatcherServlet的前世今生
- 用Python的requests库作接口测试——上传文件
- Git远程仓库学习笔记
- LeetCode OJ 之 Binary Tree Paths(二叉树路径)
- Sublime Text 3 支持的热门插件推荐
- OC之继承
- Java构造和解析Json数据的两种方法详解一
- Command Injection Flaws Attack(WebGoat5.4)
- 获取系统内存显示程序
- SpringMVC源码剖析(三)- DispatcherServlet的初始化流