httplib/HTTPS Post Problem

Discussion in 'Python' started by michaelparkin@gmail.com, Jul 11, 2005.

  1. Guest

    Hi,

    Sorry to post what might seem like a trivial problem here, but its
    driving me mad!

    I have a simple https client that uses httplib to post data to a web
    server.

    When I post over http & https using curl the data is recieved by the
    web server with no problems.

    When I post using my python client the headers get there, but the body
    of the message does not.

    My code is pretty standard and has the format:


    httplib.HTTPSConnection.debuglevel = 1
    connection = httplib.HTTPSConnection(host_name, key_file = key,
    cert_file = cert)
    connection.putrequest("POST", path)
    connection.putheader("Content-Length", str(len(body)))

    ....(some more headers)...

    connection.endheaders()
    connection.send(body)

    response = connection.getresponse()
    connection.close()

    (some code has been removed for clarity)..

    I can see in the debug messages the body getting sent, but nothing
    arrives at
    the server...

    I think I would understand whats going on better if I knew how Python
    uses the
    underlying socket - does it

    a) open the socket, send the header & body together or
    b) send the header, wait, then send the body?

    I think the answer to this question solve my problem - can anyone help?

    Thanks.

    p.s. I'm using Python 2.3.3 [GCC 3.3.3 (SuseLinx)]
    , Jul 11, 2005
    #1
    1. Advertising

  2. Am Mon, 11 Jul 2005 06:29:23 -0700 schrieb michaelparkin:

    > Hi,
    >
    > Sorry to post what might seem like a trivial problem here, but its
    > driving me mad!
    >
    > I have a simple https client that uses httplib to post data to a web
    > server.
    >
    > When I post over http & https using curl the data is recieved by the
    > web server with no problems.
    >
    > When I post using my python client the headers get there, but the body
    > of the message does not.


    Hi,

    can you look at the access log of the server? A slash at the
    end of a URL is important (www.google.com/ is different from
    www.google.com)

    response = connection.getresponse()
    What does "print response" do?

    You can listen on the wire with ethereal (Capture, then "follow tcp-stream")

    HTH,
    Thomas


    --
    Thomas G├╝ttler, http://www.thomas-guettler.de/
    Thomas Guettler, Jul 11, 2005
    #2
    1. Advertising

  3. Am Montag, den 11.07.2005, 06:29 -0700 schrieb :
    > Hi,
    >
    > Sorry to post what might seem like a trivial problem here, but its
    > driving me mad!
    >
    > I have a simple https client that uses httplib to post data to a web
    > server.
    >
    > When I post over http & https using curl the data is recieved by the
    > web server with no problems.


    Just a curious guess: Are you behind a proxy? If so, it's a known and
    never fixed bug from Python 1.5 times ;)

    You might also try to use PyCurl.

    Andreas

    >
    > When I post using my python client the headers get there, but the body
    > of the message does not.
    >
    > My code is pretty standard and has the format:
    >
    >
    > httplib.HTTPSConnection.debuglevel = 1
    > connection = httplib.HTTPSConnection(host_name, key_file = key,
    > cert_file = cert)
    > connection.putrequest("POST", path)
    > connection.putheader("Content-Length", str(len(body)))
    >
    > ...(some more headers)...
    >
    > connection.endheaders()
    > connection.send(body)
    >
    > response = connection.getresponse()
    > connection.close()
    >
    > (some code has been removed for clarity)..
    >
    > I can see in the debug messages the body getting sent, but nothing
    > arrives at
    > the server...
    >
    > I think I would understand whats going on better if I knew how Python
    > uses the
    > underlying socket - does it
    >
    > a) open the socket, send the header & body together or
    > b) send the header, wait, then send the body?
    >
    > I think the answer to this question solve my problem - can anyone help?
    >
    > Thanks.
    >
    > p.s. I'm using Python 2.3.3 [GCC 3.3.3 (SuseLinx)]
    >


    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.1 (GNU/Linux)

    iD8DBQBC1Yh5HJdudm4KnO0RAn32AKDhuPqPLTUh8Cz3vRNtcMRZDfHSUgCeMzfU
    zfNiyFIHDcosx5aNLAWLuNM=
    =aJGI
    -----END PGP SIGNATURE-----
    Andreas Kostyrka, Jul 13, 2005
    #3
  4. Have you tried using pycurl? That may be an easier way to port over your CURL
    code directly. Relatively easy to use, too.

    -Pete

    wrote:

    > Hi,
    >
    > Sorry to post what might seem like a trivial problem here, but its
    > driving me mad!
    >
    > I have a simple https client that uses httplib to post data to a web
    > server.
    >
    > When I post over http & https using curl the data is recieved by the
    > web server with no problems.
    >
    > When I post using my python client the headers get there, but the body
    > of the message does not.
    >
    > My code is pretty standard and has the format:
    >
    >
    > httplib.HTTPSConnection.debuglevel = 1
    > connection = httplib.HTTPSConnection(host_name, key_file = key,
    > cert_file = cert)
    > connection.putrequest("POST", path)
    > connection.putheader("Content-Length", str(len(body)))
    >
    > ...(some more headers)...
    >
    > connection.endheaders()
    > connection.send(body)
    >
    > response = connection.getresponse()
    > connection.close()
    >
    > (some code has been removed for clarity)..
    >
    > I can see in the debug messages the body getting sent, but nothing
    > arrives at
    > the server...
    >
    > I think I would understand whats going on better if I knew how Python
    > uses the
    > underlying socket - does it
    >
    > a) open the socket, send the header & body together or
    > b) send the header, wait, then send the body?
    >
    > I think the answer to this question solve my problem - can anyone help?
    >
    > Thanks.
    >
    > p.s. I'm using Python 2.3.3 [GCC 3.3.3 (SuseLinx)]
    Peter A. Schott, Jul 14, 2005
    #4
  5. Guest

    Thanks for the replies, Andreas and Peter.

    Andreas Kostyrka wrote:

    <snip>

    > Just a curious guess: Are you behind a proxy? If so, it's a known and
    > never fixed bug from Python 1.5 times ;)


    No, I'm not behind a proxy - the server is on the same PC as my client
    (while I'm testing!).

    > You might also try to use PyCurl.


    I've quickly read about PyCurl, but it only seems to allow HTTP HEAD,
    GET, POST and PUT methods - though please correct me if I'm wrong.

    I'd like to use httpLib in Python as I also need the DELETE method and
    the possibility of adding some extra headers and extra methods (I'm
    working on something like this : http://sw.nokia.com/uriqa/URIQA.html
    that allows MGET, MPUT, MPOST, etc.).

    I've done some more testing and still can't work out why Python
    operates differently to other http clients... any ideas?

    Thanks,

    Michael.

    <snip>
    , Jul 22, 2005
    #5
    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. Manish Jethani
    Replies:
    0
    Views:
    534
    Manish Jethani
    Dec 21, 2003
  2. Robert
    Replies:
    0
    Views:
    690
    Robert
    Apr 5, 2005
  3. runningwild

    httplib and HTTPS Connections

    runningwild, Oct 17, 2006, in forum: Python
    Replies:
    5
    Views:
    972
    Heikki Toivonen
    Oct 19, 2006
  4. Axel
    Replies:
    8
    Views:
    1,060
    Adrienne Boswell
    Apr 27, 2009
  5. jotto
    Replies:
    4
    Views:
    373
    jotto
    Oct 2, 2006
Loading...

Share This Page