[Twisted-Python] Newbie: Help with twisted.web, HTTPClient

I just started playing with Twisted last week; great stuff! My question is this: I have an .rpy file, which defines a Resource. As part of this Resource's render method, I need to perform an http GET against another server, which of course causes the twisted.web server to block. From looking through the source code, it looks like the HTTPClient should be what I need to perform a non-blocking http GET from within my resource, but I cannot find any information on how to use it; just creating an instance and doing sendCommand fails, stating that there is no transport. I guess I could just use httplib.HTTPConnection, but I'd have to run that in a separate thread in order to prevent blocking, and it just seems like I shouldn't need to use threads for something so simple. Any advice or help would be greatly appreciated, thanks. Daniel Burr

On Sat, 2002-07-27 at 13:11, Daniel Burr wrote:
Check out doc/examples/qtdemo.py; it has a HTTPClient example (class TwistzillaClient). Basically, you'll want your render method to 1) instantiate your HTTPClient subclass, making sure to pass your 'request' object to it (and make sure to connect it), 2) return web.server.NOT_DONE_YET, 3) in the 'handleResponse' method of your HTTPClient subclass, write all the data with 'request.write(data)', then call 'request.finish()' so twisted.web knows you're done. HTH. -- Chris Armstrong << radix@twistedmatrix.com >> http://twistedmatrix.com/users/carmstro.twistd/

On Sat, 2002-07-27 at 13:11, Daniel Burr wrote:
Check out doc/examples/qtdemo.py; it has a HTTPClient example (class TwistzillaClient). Basically, you'll want your render method to 1) instantiate your HTTPClient subclass, making sure to pass your 'request' object to it (and make sure to connect it), 2) return web.server.NOT_DONE_YET, 3) in the 'handleResponse' method of your HTTPClient subclass, write all the data with 'request.write(data)', then call 'request.finish()' so twisted.web knows you're done. HTH. -- Chris Armstrong << radix@twistedmatrix.com >> http://twistedmatrix.com/users/carmstro.twistd/
participants (2)
-
Christopher Armstrong
-
Daniel Burr