python requests 库请求带有文件参数的接口实例
作者:吕海洋 时间:2022-04-23 09:12:10
有些接口参数是一个文件格式,比如fiddler 抓包参数如下显示
这个接口的 form-data fiddler 显示的和不带文件参数的接口有明显区别,显示的不是简单的键值对,所以我们也不能只通过 data给接口传参,需要再value为<file>的参数通过 files传参
data = {
"CSRFName": “CSRFName”,
"CSRFToken": “CSRFToken”,
"importType": "XML",
"hit_criteria": "name",
"action_on_duplicated_name": "generate_new",
"useRecursion": "0",
"bIntoProject": "0",
"containerID": "4956",
"MAX_FILE_SIZE": "409600",
"UploadFile": "上传文件"
}
files = {"uploadedFile": open(file_name, "rb")}
r = session.post(url=url, data=data, files=files)
这样我们通过requests 再次请求接口,通过fiddler 抓包,验证一下requests的请求是不是和原始的请求一致。
fiddler 显示的form data和原始请求一致,说明我们请求参数是正确的。
来源:https://blog.csdn.net/wuchenlhy/article/details/81164950
标签:python,requests,接口
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python装饰器使用方法实例
2022-12-14 11:24:07
Python Json数据文件操作原理解析
2022-10-27 19:00:32
![](https://img.aspxhome.com/file/2023/6/81556_0s.png)
sql exist的妙用
2007-11-08 11:47:00
python 图片验证码代码
2023-07-22 00:33:19
使用Python生成url短链接的方法
2021-05-05 02:55:12
Flask-Sqlalchemy的基本使用详解
2023-06-16 19:40:02
![](https://img.aspxhome.com/file/2023/4/76044_0s.jpg)
Django修改端口号与地址的三种方式
2023-06-22 00:48:27
![](https://img.aspxhome.com/file/2023/3/60983_0s.png)
一步步教你用Python实现2048小游戏
2023-02-15 20:51:29
![](https://img.aspxhome.com/file/2023/9/82809_0s.jpg)
php源码的使用方法讲解
2023-06-17 21:47:02
网站细节论(1)--阅读的细节
2007-12-21 12:16:00
![](https://img.aspxhome.com/file/UploadPic/200712/21/20071221122819275s.gif)
python基于TCP实现的文件下载器功能案例
2021-12-30 05:14:26
关于python pycharm中输出的内容不全的解决办法
2023-09-23 16:45:26
![](https://img.aspxhome.com/file/2023/7/103257_0s.jpg)
基于python获取本地时间并转换时间戳和日期格式
2021-02-23 17:30:06
![](https://img.aspxhome.com/file/2023/9/86539_0s.png)
介绍讲解MySQL安装下载登录
2010-10-25 20:34:00
在Matplotlib图中插入LaTex公式实例
2023-09-05 12:23:38
![](https://img.aspxhome.com/file/2023/4/99244_0s.jpg)
如何对MySQL数据库日志文件进行维护
2009-02-04 13:23:00
Python实现基于权重的随机数2种方法
2022-10-13 03:25:40
DreamweaverMX2004的一句话技巧
2009-05-22 18:23:00
python中关于时间和日期函数的常用计算总结(time和datatime)
2022-01-02 05:50:08
python 字典有序并写入json文件过程解析
2021-08-21 21:12:01
![](https://img.aspxhome.com/file/2023/7/101497_0s.png)