[英]python request- file upload
我能够使用邮递员,并使用图像和字符串参数执行发布请求。 如果我从邮递员复制python代码并运行它,我将无法执行相同的操作。
import requests
url = "yyyyyyyyyy"
querystring = {"param1":"xxxxx"}
payload = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"queryFile\"; filename=\"file.jpg\"\r\nContent-Type: image/jpeg\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--"
headers = {
'content-type': "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
'Authorization': "Bearer yyyyyyyyyyy",
'cache-control': "no-cache",
'Postman-Token': "fffffffffff"
}
response = requests.request("POST", url, data=payload, headers=headers, params=querystring)
print(response.text)
{"message":"EMPTY_FILE_NOT_ALLOWED","status":400}
您需要通过files
参数传递对要上传的files
的引用。 请参阅python请求文件上传 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.