【问题标题】:python request- file uploadpython请求-文件上传
【发布时间】:2019-05-20 19:42:19
【问题描述】:

我能够使用邮递员并使用图像和字符串参数进行发布请求。如果我从邮递员那里复制 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}

【问题讨论】:

    标签: python api request postman


    【解决方案1】:

    您需要通过files 参数传递对要上传的文件的引用。见python requests file upload

    【讨论】:

      猜你喜欢
      • 2017-10-11
      • 2019-05-12
      • 1970-01-01
      • 2021-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-29
      相关资源
      最近更新 更多