using email.Parser for HTTP uploads

P

prefetch

hi people -

i'm new to python, but i'm quickly becoming a fan.

i'm using BaseHTTPServer and wrote a do_POST method, which i'd like to
read posted files and write them to disk. seems like it should be
simple.

well, i'm having problems - i can read the "raw" posted file, but it
has the MIME header and delimeter included. (below)

#this works, but includes all the MIME header & delimiter stuff
data = self.rfile.read(int(self.headers["content-length"]))

of course, i'd like to parse out all that nasty stuff so i can
actually get to the 'payload'. so it looks like all the docs point to
the email package for this kind of thing. so i try this:

myParser = email.Parser.Parser()
data = myParser.parse(self.rfile) # hang forever here

so, am i lame? why won't this actually work?
note that i do not want to use the cgi module - i'd like to figure out
how to make this work with just BaseHTTPServer. i should, right?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top