urllib2/httplib and email mime
Joseph
someone at arbitrary.org
Fri Aug 22 07:57:19 EDT 2003
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
More information about the Python-list
mailing list