httplib.ResponseNotReady question

Discussion in 'Python' started by Max, Nov 13, 2006.

  1. Max

    Max Guest

    Hi, Group.

    I'm not a Python programmer so this question may be really basic or
    stupid. :) I have some code that sends a simple request to an
    end-point and reads the response. That works just fine. When I put
    the code in a for loop though I get httplib.ResponseNotReady error
    message. It seems to me that I cannot call the requestor.getreply()
    multiple times on the same requestor object. Anyway, here's the part
    of my code that is causing the problem (I hope the format is
    preserved...).

    def sendRequest( msg, loops ):
    requestor = httplib.HTTP(SERVER_ADDR, SERVER_PORT)
    requestor.putrequest("POST", "/path/to/endpoint")
    requestor.putheader("Host", SERVER_ADDR)
    requestor.putheader("Content-Type", "text/xml")
    requestor.putheader("Content-Length", str(len( msg ) ) )
    requestor.endheaders()
    for i in range(loops):
    requestor.send( msg )
    print "[" + str(i) + "] Message Sent : " +
    time.strftime('%H:%M:%S', time.localtime())
    (status_code, message, reply_headers) = requestor.getreply()
    print "[" + str(i) + "] Response Received : " +
    str(status_code)
    print "[" + str(i) + "] Status : " +
    time.strftime('%H:%M:%S', time.localtime())
    print "-----[ break ]-----"

    If I run this with loops=1 then everything works fine. If I use a
    number greater than 1 then I get the error. Is there a method call
    that I need to restore the requestor object to a condition where it's
    eligible to receive another response?

    Thanks, Max
    Max, Nov 13, 2006
    #1
    1. Advertising

  2. Max wrote:

    > If I run this with loops=1 then everything works fine. If I use a
    > number greater than 1 then I get the error. Is there a method call
    > that I need to restore the requestor object to a condition where it's
    > eligible to receive another response?


    I'm pretty sure that to get a new response from the server, you need to
    make a new request.

    </F>
    Fredrik Lundh, Nov 13, 2006
    #2
    1. Advertising

  3. Max

    Max Guest

    Fredrik Lundh wrote:
    > Max wrote:
    >
    > > If I run this with loops=1 then everything works fine. If I use a
    > > number greater than 1 then I get the error. Is there a method call
    > > that I need to restore the requestor object to a condition where it's
    > > eligible to receive another response?

    >
    > I'm pretty sure that to get a new response from the server, you need to
    > make a new request.
    >
    > </F>


    I think you are right. I found a note in the documentation that says
    the connection is good for one transaction.

    Thanks, Max
    Max, Nov 13, 2006
    #3
    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. Gandalf

    httplib ResponseNotReady

    Gandalf, Oct 12, 2004, in forum: Python
    Replies:
    0
    Views:
    1,341
    Gandalf
    Oct 12, 2004
  2. Gandalf

    Re: httplib ResponseNotReady

    Gandalf, Oct 12, 2004, in forum: Python
    Replies:
    0
    Views:
    617
    Gandalf
    Oct 12, 2004
  3. Chris Rebert

    Re: ResponseNotReady exception

    Chris Rebert, Jan 3, 2009, in forum: Python
    Replies:
    1
    Views:
    430
  4. pedr0

    HTTP ResponseNotReady

    pedr0, Oct 4, 2011, in forum: Python
    Replies:
    4
    Views:
    1,060
    pedr0
    Oct 4, 2011
  5. Manu

    ResponseNotReady in httplib

    Manu, Mar 28, 2012, in forum: Python
    Replies:
    0
    Views:
    367
Loading...

Share This Page