views:

52

answers:

1

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?

A: 

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

msanders
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!
pictiPig