By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,427 Members | 1,378 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,427 IT Pros & Developers. It's quick & easy.

httplib.ResponseNotReady question

P: n/a
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

Nov 13 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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>

Nov 13 '06 #2

P: n/a
Max

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

Nov 13 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.