3

I'm sending a couple of files from an HTML form to my server which is based on BaseHTTPServer.

Within my do_POST I'm getting a string from rfile.read(length) which looks like some sort of multipart MIME string. Google is not being helpful on how I can decode this into something usable.

The output looks like this :

-----------------------------122422713313797828591978698502

Content-Disposition: form-data; name="MAX_FILE_SIZE"



1000000

-----------------------------122422713313797828591978698502

Content-Disposition: form-data; name="and_title_input"

and so on.

I've tried email.parser

from email.parser import Parser 
p=Parser()
msg=p.parsestr(s)

but msg doesn't seem to get me any nearer to my goal - it's not multipart and contains no payload.

I'm reduced to parsing the data myself - which is surely not the Pythonic way of doing things!

Have I missed something obvious? Has Google let me down? Can Stack Overflow save the day?

1 Answer 1

6

Would cgi.parse_multipart meet your need? Also see a relevant discussion on comp.lang.python.

Sign up to request clarification or add additional context in comments.

1 Comment

Yup - cgi.parse_multipart was the answer, and your link to comp.lang.python was very informative. Thanks for that. Hours of time saved, for something better!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.