urllib2/httplib and email mime

Discussion in 'Python' started by Joseph, Aug 22, 2003.

  1. Joseph

    Joseph Guest

    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
     
    Joseph, Aug 22, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Oliver
    Replies:
    0
    Views:
    582
    Michael Oliver
    Jan 13, 2006
  2. RajNewbie
    Replies:
    2
    Views:
    740
    RajNewbie
    Dec 1, 2008
  3. ak
    Replies:
    7
    Views:
    5,824
  4. Bob Fnord
    Replies:
    2
    Views:
    870
    Bob Fnord
    May 12, 2011
  5. ecureuil
    Replies:
    0
    Views:
    361
    ecureuil
    May 28, 2006
Loading...

Share This Page