python 如何通过POST上传EXCEL文件到网站,不懂如何写,抓包软件抓到RAW信息如下:
POST http://10.184.19.2:8000/api/tc-config-biz/FileOperateController/uploadFiles HTTP/1.1
Host: 10.184.19.2:8000
Authorization: Bearer 580131a9-30c9-4b39-9d82-c1af8341eeb5
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary26TicDu5Peqo2sb7
Accept: /
Origin: http://10.184.19.2:8000/
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
------WebKitFormBoundary26TicDu5Peqo2sb7
Content-Disposition: form-data; name="attachment"
{"url":"sheet/gt/","bucketName":"nctc"}
------WebKitFormBoundary26TicDu5Peqo2sb7
Content-Disposition: form-data; name="context"
{"userUuid":"pangyou","userName":"pangyou","userIp":"","serverId":"","metaUuid":""}
------WebKitFormBoundary26TicDu5Peqo2sb7
Content-Disposition: form-data; name="file"; filename="产品使用情况.xlsx"
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
```python
header = {
'Authorization':'bearer 580131a9-30c9-4b39-9d82-c1af8341eeb5',
'Connection': 'keep-alive',
'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundary26TicDu5Peqo2sb7',
'Host': '10.184.19.2:8000',
'Origin': 'http://10.184.19.2:8000',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'
}
#上传文件
url='http://10.184.19.2:8000/api/tc-config-biz/FileOperateController/uploadFiles'
filename='产品使用情况.xlsx'
filepath='D:/pycharm/yunwei_ceshi/产品使用情况.xlsx'
body={
'bucketName':"nctc",
"url":"sheet/gt/"
}
with open(filepath,'rb') as f_:
m= MultipartEncoder(
fields={
"userUuid": "pangyou",
"userName": "pangyou",
"userIp": "",
"serverId": "", "metaUuid": "",
'file':(filename,f_,'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')}
)
response=requests.post(url,headers=header,json=body,data=m,timeout=None,verify=False)
print(m.content_type)
print (response.text)
```