python接口自动化-requests-toolbelt处理multipart/form-data
1、requests-toolbelt官方文档:https://pypi.org/project/requests-toolbelt/
2、环境安装
pip install requests-toolbelt
3、使用
使用的时候按照格式来就可以了
multipart/form-data传文件
from requests_toolbelt import MultipartEncoder
import requests m = MultipartEncoder(
fields={'field0': 'value',
'field1': 'value',
'field2': ('文件名称', open('文件地址/file.py', 'rb'), 'text/plain')}
) r = requests.post('http://httpbin.org/post',
data=m,
headers={'Content-Type': m.content_type})
multipart/form-data表单提交(传非文件)
from requests_toolbelt import MultipartEncoder
import requests m = MultipartEncoder(
fields={'field0': 'value',
'field1': 'value'}) r = requests.post('http://httpbin.org/post',
data=m,
headers={'Content-Type': m.content_type})
参数也可以使用list类型
from requests_toolbelt import MultipartEncoder
import requests m = MultipartEncoder(
fields = [
('source', ('f1.ext', f1, 'application/x-example-mimetype'),
('source', ('f2.ext', f2, 'application/x-example-mimetype'),
]
) r = requests.post('http://httpbin.org/post',
data=m,
headers={'Content-Type': m.content_type})
python接口自动化-requests-toolbelt处理multipart/form-data的更多相关文章
- Python接口自动化--requests 2
# _*_ encoding:utf-8 _*_ import json import requests #post请求 payload = {"cindy":"hell ...
- 【python接口自动化-requests库】【三】优化重构requests方法
一.重构post请求方法 上一张讲了如何使用requests库发送post请求,但是有时候,我们写脚本,不可能这么简单,代码完全不可复用,重复工作,那我们是不是可以想象,把我们的get,post请求, ...
- 【python接口自动化-requests库】【二】requests库简单使用(入门)
一.post请求 前面讲了,我们get请求的时候,引入requests的包,然后直接使用get方法,那么post是不是一样的? 1.首先我们先引入requests import requests 2. ...
- 【python接口自动化-requests库】【一】requests库安装
1.概念 requests 是用Python语言编写,基于 urllib,采用 Apache2 Licensed 开源协议的 HTTP 库.它比 urllib 更加方便,可以节约我们大量的工作,完全满 ...
- Python接口自动化--requests 1
# _*_ encoding:utf-8 _*_ import requests #请求博客园首页,无参数的get请求 r = requests.get('http://www.cnblogs.com ...
- python接口自动化(十)--post请求四种传送正文方式(详解)
简介 post请求我在python接口自动化(八)--发送post请求的接口(详解)已经讲过一部分了,主要是发送一些较长的数据,还有就是数据比较安全等.我们要知道post请求四种传送正文方式首先需要先 ...
- python接口自动化25-发xml格式post请求
前言 post请求相对于get请求多一个body部分,body部分常见的数据类型有以下四种(注意是常见的,并不是只有4种) application/x-www-form-urlencoded appl ...
- python接口自动化16-multipart/form-data上传图片
前言 在提交表单操作的时候,经常会遇到图片上传的操作,图片上传是一个单独的接口,本篇以禅道为例,介绍如何上传图片 上传接口 1.以禅道上提交bug为例,在选择图片时,点确定按钮,就是上传图片了 2.用 ...
- python接口自动化-Cookie_绕过验证码登录
前言 有些登录的接口会有验证码,例如:短信验证码,图形验证码等,这种登录的验证码参数可以从后台获取(或者最直接的可查数据库) 获取不到也没关系,可以通过添加Cookie的方式绕过验证码 前面在“pyt ...
- python接口自动化28-requests-html爬虫框架
前言 requests库的好,只有用过的人才知道,最近这个库的作者又出了一个好用的爬虫框架requests-html.之前解析html页面用过了lxml和bs4, requests-html集成了一些 ...
随机推荐
- codewars--js--ten minutes walk
题目: You live in the city of Cartesia where all roads are laid out in a perfect grid. You arrived ten ...
- js 预编译
js 运行代码的时候分为几个步骤:语法分析 ==>预编译 ==>解释执行 语法解析:通篇扫描代码,查看语法是否出错 解释执行:读一行 - 解释一行 - 执行一行 预编译执行的操作: // ...
- ES6 - 基础学习(8): Promise 对象
概述 Promise是异步编程的一种解决方案,比传统的解决方案(多层嵌套回调.回调函数和事件)更强大也更合理.从语法上说,Promise是一个对象,从它可以获取异步操作的消息,Promise 还提供了 ...
- 【React Native错误集】* What went wrong: Execution failed for task ':app:installDebug'.
错误1:* What went wrong: Execution failed for task ':app:installDebug'. > com.android.builder.testi ...
- Oracle11以后的行列转换
Oracle11以后,行列转换有了新的方法. 下面的是已经疏通过的代码,请放心使用... With AA as ( Select A,B,C,row_number() over (partition ...
- Zookeeper机制
顾名思义 zookeeper 就是动物园管理员,他是用来管 hadoop(大象).Hive(蜜蜂).pig(小 猪)的管理员, Apache Hbase 和 Apache Solr 的分布式集群都用到 ...
- SpringCloud之eureka注册中心入门
eureka注册中心 一.基本概念 SpringCloud封装 了Netflix公司的eureka作为自己微服务的注册中心.这个注册中心和dubbo中的zookeeper很相似,简单来说,只要你可以将 ...
- notepad中运行python, --kali安装后出现乱码
notepad中运行python cmd /k python "$(FULL_CURRENT_PATH)" & ECHO. & PAUSE & EXIT - ...
- VBA-FileToFileUpdate
Public Sub FileToFileUpdate(ByVal fileName As String, ByVal strFrm As String, ByVal strTo As String) ...
- jQuery---链式编程
链式编程 设置性操作:可以链式编程 获取性操作,不能链式,因为获取性操作,数值,字符串,返回值是不是一个jq对象. $(function () { //设置性操作:可以链式编程 //获取性操作,不 ...