httplib.ResponseNotReady question

Max Google at Bodoin.com
Mon Nov 13 13:05:12 EST 2006


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




More information about the Python-list mailing list