[Twisted-Python] Re: Running a HTTP client connection through a SOCKS proxy

Phil Mayers p.mayers at imperial.ac.uk
Fri Jul 25 04:03:18 EDT 2008

On Fri, Jul 25, 2008 at 04:05:30PM +1000, Tim Allen wrote:
>On Thu, Jul 24, 2008 at 11:49:56AM +0100, nnp wrote:
>> Hrm, OK....I'm not sure if I have an odd view of the world or whether
>> supporting HTTP proxies isn't all that important. Aren't HTTP proxies
>> fairly common in large organisations and universities?
>HTTP proxies are very common; I guess nobody who's needed one has yet
>had time to sit down and write support.

It's not hard:


from twisted.internet import reactor
from twisted.web import client

def got(page):
    print "got", repr(page)
    reactor.callLater(0.1, reactor.stop)
def failed(err):
    print err.getErrorMessage()
    reactor.callLater(0.1, reactor.stop)

class ProxyClientFactory(client.HTTPClientFactory):
    def setURL(self, url):
	# do the normal stuff
	client.HTTPClientFactory.setURL(self, url)
	# then re-set the path to be the full url
	self.path = url

cf = ProxyClientFactory('http://www.google.com/')
cf.deferred.addCallbacks(got, failed)

reactor.connectTCP('wwwcache1.ic.ac.uk', 3128, cf)

More information about the Twisted-Python mailing list