xmlrpc via proxy in XML-RPC HOWTO

Andy Bulka abulka at netspace.net.au
Mon Jul 30 14:24:47 CEST 2001


I'm trying to get xmlrpc to work through a firewall/proxy.  The python
example at XML-RPC HOWTO at
http://xmlrpc-c.sourceforge.net/xmlrpc-howto/xmlrpc-howto-python-client.html
 gives the following client code shows how to call an XML-RPC server from
Python and get an XML result.

    import xmlrpclib
    # Create an object to represent our server.
    server_url = 'http://xmlrpc-c.sourceforge.net/api/sample.php';
    server = xmlrpclib.Server(server_url);

    # Call the server and get our result.
    result = server.sample.sumAndDifference(5, 3)
    print "Sum:", result['sum']
    print "Difference:", result['difference']

I'm trying to get it to work through a firewall/proxy and have replaced the
line
    server = xmlrpclib.Server(server_url);
with
    server = xmlrpclib.Server(server_url, transport=UrllibTransport() );

and defined the following class to break through the proxy / firewall

class UrllibTransport(xmlrpclib.Transport):
	def request(self, host, handler, request_body):
		import urllib
                urlopener = urllib.FancyURLopener( {'http' :
'http://www-proxy.BLAH.au:8080' } )
		urlopener.addheaders = [('User-agent', self.user_agent)]
		f = urlopener.open('http://'+host+handler, request_body)
		return(self.parse_response(f))

But its not working - raising an exception.  I've pieced together this
almost-solution from fragments on the web and would appreciate help getting
it to work.

thanks
Andy Bulka






More information about the Python-list mailing list