[Twisted-Python] access an XMLRPC service through an HTTP proxy
solipsis at pitrou.net
Wed Dec 29 07:49:17 EST 2004
> I'm using twisted.web.xmlrpc.Proxy to connect to an XMLRPC service.
> Unfortunately there are situations in which I have to go through an HTTP
> proxy, yet there doesn't seem to be an option for this (and looking at
> the code, the connection to the remote server is quite "harwired").
Replying to myself... The following seems to work (I didn't test with
import twisted.web.xmlrpc as xmlrpc
A Proxy for making remote XML-RPC calls accross an HTTP proxy.
Pass the URL of the remote XML-RPC server to the constructor,
as well as the proxy host and port.
Use proxy.callRemote('foobar', *args) to call remote method
'foobar' with *args.
def __init__(self, reactor, url, proxy_host, proxy_port):
self.reactor = reactor
self.url = url
self.proxy_host = proxy_host
self.proxy_port = proxy_port
parts = urlparse.urlparse(url)
self.remote_host = parts
self.secure = parts == 'https'
def callRemote(self, method, *args):
factory = xmlrpc.QueryFactory(self.url, self.remote_host, method, *args)
from twisted.internet import ssl
self.reactor.connectTCP(self.proxy_host, self.proxy_port, factory)
More information about the Twisted-Python