测试文件上传接口

import requests

url = "http://xxxx/api/upload/opinion"
url_login = "http://xxxx/api/auth/login"
data = {"username":"test3","password":"123456"}
res = requests.post(url=url_login,data=data)
token = res.json()['data']['token']

headers = {"Authorization":"bearer %s" % token,
          }
file1 = open('20191113.docx','rb')

files = {'file':('20191113.docx',file1,'application/vnd.openxmlformats-officedocument.wordprocessingml.document')}
"""
application/vnd.openxmlformats-officedocument.wordprocessingml.document是抓包时得到
""" data1
= {"category":"专项工程", "name":"载人空间站系统", "stage":"工程研制", "version":"V20191025-144234(评审前)", } res = requests.post(url=url,headers = headers,data=data1,files=files) print(res.json()["msg"])

显式的设置文件名、文件类型和请求头

猜你喜欢

转载自www.cnblogs.com/wbw-test/p/11989323.html