httplib.ResponseNotReady question

M

Max

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
 
F

Fredrik Lundh

Max said:
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>
 
M

Max

Fredrik said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top