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

Christopher Armstrong carmstro at twistedmatrix.com
Sun Jul 28 14:12:29 EDT 2002


On Sat, 2002-07-27 at 13:11, Daniel Burr wrote:
> 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.

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 at twistedmatrix.com >>
                http://twistedmatrix.com/users/carmstro.twistd/





More information about the Twisted-Python mailing list