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. Advertisements

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. CJ
    Replies:
    1
    Views:
    1,855
    Andrew Thompson
    Oct 29, 2004
  2. Michael Oliver
    Replies:
    0
    Views:
    660
    Michael Oliver
    Jan 13, 2006
  3. RajNewbie
    Replies:
    2
    Views:
    964
    RajNewbie
    Dec 1, 2008
  4. ak
    Replies:
    7
    Views:
    7,059
  5. Bob Fnord
    Replies:
    2
    Views:
    957
    Bob Fnord
    May 12, 2011
  6. ecureuil
    Replies:
    0
    Views:
    619
    ecureuil
    May 28, 2006
  7. Replies:
    2
    Views:
    576
    Tintin
    Jan 5, 2007
  8. Brian Raymond
    Replies:
    0
    Views:
    219
    Brian Raymond
    Apr 22, 2013
Loading...