[英]Python - API POST with Form-Data file upload
郵遞員我已經嘗試了所有方法來復制使用 Python 工作的郵遞員 POST,但我沒有成功。 我收到了 500 回,當我打印請求時,我沒有發現任何問題。 有什么建議?
```
filename1="untitled.png"
filename="untitled.png"
location = "C:\\myfiles\\"
#files = {"file":(filename1,open(location+'/'+filename,"rb"),'application-type')}
#files = {"file":(filename1,open(location+'/'+filename,"rb"))}
#files = {"file":(filename1, open(location+'/'+filename,'rb'),'application-type')}
files = {'file': (filename1, open(location+'/'+filename,'rb'))}
payload = {'': {
"DateIssued": "2020-02-22T14:35:40.760026-08:00",
"Category":None,
"Title":"Report",
"Title2":"MyReports"
}}
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'PublishService-Api-Key': 'myAPIKey'
}
req = requests.request('POST',"http://myurl.com/PublishService/api/docs/", headers=headers, data=payload, files=files)
print(req)
```
只需從標題中刪除Content-Type
。
headers = {
'PublishService-Api-Key': 'myAPIKey'
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.