“message”:“所需的请求部分“file\”不存在”

2024-10-08 16:41:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用REST和python上传一个文件。我能用邮递员。但是,当我从Postman获取Python代码并尝试使用requests模块自己执行它时,我得到了以下错误。请帮忙。在

import requests

url = "https://url******"

payload = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: 
form-data; name=\"file\"; filename=\"Path to file"\r\n\r\n\r\n------
WebKitFormBoundary7MA4YWxkTrZu0gW--"
headers = {
    'content-type': "multipart/form-data; boundary=----
WebKitFormBoundary7MA4YWxkTrZu0gW",
    'auth_token': auth_token,
    'cache-control': "no-cache",
}

response = requests.request("POST", url, data=payload, headers=headers, 
verify=False)

print(response.text)

>>> response.text
u'{"message":"Required request part \'file\' is not 
present","detailedMessage":"
","errorCode":-1,"httpStatus":500,"moreInfo":""}'

Tags: textformtokenauthresturlcachedata
1条回答
网友
1楼 · 发布于 2024-10-08 16:41:39

似乎错误出现在您发布到的服务器上,因为获取了错误的数据。 我没有你发布的网址,所以我不知道正确的数据形式。 试着把参考书读清楚对你有帮助。在

相关问题 更多 >

    热门问题