I have Java spring server that requires the Content-Type
of the requests being sent to the server to be multipart/form-data
.
I can correctly send requests to the server with postman:
However, I got The current request is not a multipart request
error when trying to send the request with requests
module in python3.
My python code is:
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)
If I add 'Content-Type': 'multipart/form-data'
to the header of the request, the error message then becomes Could not parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
.
How can I make the same request as postman sends with python?