0
我想使用REST和python上传文件。我能用邮差做。但是当我从Postman获取Python代码并尝试使用请求模块自己执行它时,出现以下错误。请帮忙。“消息”:“必需的请求部分文件不存在”
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":""}'
嗨,我可以上传使用邮递员使用该网址。所以,url不应该是一个问题。 –