我正在尝试在python中发布多部分请求,这给了我不受支持的媒体类型错误415。我正在使用请求来这样做。这是我的代码: 导入请求
url = "http://localhost/myserver/RestAPI/v1/mymessages"
querystring = {"Keyapp":"key","Secret":"somepasswd"}
headers = {
'Authorization': "Basic Y29sbGVjdG9yLzFGQUFCOEFENUIxOTc",
'Content-Type': "application/xml;charset=utf-8",
'Accept': "application/xml",
'Accept-Charset': 'UTF-8',
'content-type': "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
}
xmlFile = 'C:\\myXMLfile.xml'
txtFile = 'C:\\mytextfile.txt'
multiple_files = [
('metadata',('myXMLfile.xml',open(xmlFile,'rb'), 'application/xml')),
('0',('mytextfile.txt', open(txtFile, 'rb'), 'text/plain'))
]
response = requests.request("POST", url, files=multiple_files, headers=headers, params=querystring)
print(response.text)
print(response.request.body)
print(response.reason)
print(response.status_code)
任何人都可以帮忙。我被困住了。