У меня есть сервер Java Spring, который требует Content-Type
запросов, отправляемых на сервер, равным multipart/form-data
.
Я могу правильно отправлять запросы на сервер с почтальоном:


Однако при попытке отправить запрос с модулем requests
я получил ошибку The current request is not a multipart request
в Python3.
Мой код Python:
import requests
headers = {
'Authorization': 'Bearer auth_token'
}
data = {
'myKey': 'myValue'
}
response = requests.post('http://127.0.0.1:8080/apiUrl', data=data, headers=headers)
print(response.text)
Если я добавлю 'Content-Type': 'multipart/form-data'
в заголовок запроса, сообщение об ошибке станет Could not parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
.
Как я могу сделать тот же запрос, что и почтальон с Python?