[Twisted-Python] web client and proxy

Amaury Forgeot d'Arc amauryfa at gmail.com
Thu Jun 19 10:06:59 EDT 2008

Olivier Fournier wrote:
> Hi,
> My english is very bad, sorry...
> I don't understand how to access to a web server behind a proxy from
> web.client ?
> somebody could explain me how to do?
> thanks

Here is a modified version of web.client.getPage() that I use behind a proxy:

def getPage(url, contextFactory=None, *args, **kwargs):
    scheme, host, port, path = _parse(url)
    factory = HTTPClientFactory(url, *args, **kwargs)
    if 1: # use a proxy
        host, port = 'proxy', 6060
        factory.path = url
    if scheme == 'https':
        from twisted.internet import ssl
        if contextFactory is None:
            contextFactory = ssl.ClientContextFactory()
        reactor.connectSSL(host, port, factory, contextFactory)
        reactor.connectTCP(host, port, factory)
    return factory.deferred

Hope this helps,

Amaury Forgeot d'Arc

More information about the Twisted-Python mailing list