python requests 模拟postman发送post请求form-data类型上传文件
postman请求方式如下:
requests模块对应的请求代码如下:
url="" #url路径(根据自己的补充,这里暂未填写)
begintime="2021-07-09 11:53:02"
endtime="2021-07-09 11:57:00"
data = {"begin_time": str_begintime, "end_time": str_endtime}
req = json.dumps(data)
m = MultipartEncoder(
fields={'data': ('', req, 'application/json'),
'file': (
"filename",#上传的文件名,这里为filename
open(i.get("record_filename"), "rb"),
'application/g09-data' #根据上传的文件类型填写)})
# 调用api
response = requests.post(url=url, headers={'Content-Type': m.content_type}, data=m)