我正在尝试将CSV文件发布到API服务并出现错误。在API参考中,有人说我应该为“ multipart”提供类型为“ File”的“ file”参数。我应该在哪里提供该文件参数?
b'{“时间戳”:1543489711533,“原因”:“ GENERAL_ERROR”,“描述”:“引发了异常:必需的MultipartFile参数\ u0027file \ u0027不存在”,“ detailMessage”:“引发了异常:必需的MultipartFile参数\ u0027file \ u0027不存在“,” stackTrace“:[],” suppressedExceptions“:[]}'
代码如下:
url = url_api
querystring = {"grant_type":"client_credentials" }
headers = {'content-type': "application/x-www-form-urlencoded",
'authorization': key
}
response = requests.request("POST", url, headers=headers, params=querystring)
token = ast.literal_eval(response.text)["access_token"]
print(token)
querystring = {"accountId":store_id
}
payload = {"fileName": File_Name,
"file": (File_Name, open(File_Name, 'rb'))}
headers = {
'authorization': "bearer " + str(token)}
url = url + "/feed"
response2 = requests.request("POST", url, data=payload, headers=headers,
files = {'file': (File_Name, open(File_Name, 'rb')})