urllib2/httplib and email mime

J

Joseph

Hello All,

I am using email to create a multipart message that I need to post to
a url.

I have been doing it semi-manually with httplib:

h = httplib.HTTP(self.host)
h.putrequest("POST", self.url)
h.putheader("Host", self.host)
# Lot of other headers here...
# Here is where it gets ugly
h.putheader("Content-Type", 'multipart/mixed;
boundary="===============0814072620=="'
# Where I had to figure out what that was from my Message object I
created earlier.

# Now do ugly stuff to strip off the first 2 lines from my
msg.as_string()
# (omited due to modesty... It's too ugly)
h.putheader("Content-length", str(len(stripped_msg)))
h.endheaders()
h.send(stripped_msg)

Can someone sugest a cleaner way of doing this sort of thing using
urllib2? The problem is getting the Content-Type header from my email
object to be used by urllib2 as an http header.

Thanks,

Joseph
 

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,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top