Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multipart data POST using python requests: no multipart boundary was found

I have a form-data as well as file to be sent in the same POST. For ex, {duration: 2000, file: test.wav}. I saw the many threads here on multipart/form-data posting using python requests. They were useful, especially this one.

My sample request is as below:

    files = {'file': ('wavfile', open(filename, 'rb'))}     data = {'duration': duration}     headers = {'content-type': 'multipart/form-data'}     r = self.session.post(url, files=files, data=data, headers=headers) 

But when I execute the above code, I get this error:

5:59:55.338 Dbg 09900 [DEBUG] Resolving exception from handler [null]: org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found.

So my questions are: 1) How can I see the content of the request being sent? Couldn't use wireshark, its not across the network. 2) why is the boundary missing in the encoded data? Did I miss anything, please point out.

like image 361
jeera Avatar asked Jul 01 '13 23:07

jeera


2 Answers

You should NEVER set that header yourself. We set the header properly with the boundary. If you set that header, we won't and your server won't know what boundary to expect (since it is added to the header). Remove your custom Content-Type header and you'll be fine.

like image 191
Ian Stapleton Cordasco Avatar answered Oct 05 '22 16:10

Ian Stapleton Cordasco


Taking out the Content-Type header with explicit "multipart/form-data" worked!

like image 32
Anirban Kundu Avatar answered Oct 05 '22 15:10

Anirban Kundu