Linux Online Advertisement
[ Register ]

[ Applications ]
[ Documentation ]
[ Distributions ]
[ Download Info ]
[ General Info ]
[ Book Store ]
[ Courses ]
[ News ]
[ People ]
[ Hardware ]
[ Vendors ]
[ Projects ]
[ Events ]
[ User Groups ]
[ User Area ]

Moving to Linux: Kiss the Blue Screen of Death Goodbye!

[ About Us ]
[ Home Page ]
[ Advertise ]

Using XML-RPC with Python

7. Using XML-RPC with Python

Fredrik Lundh has provided an excellent XML-RPC library for Python.

To install, download the latest version. You can either stick the *.py files in the same directory as your Python code, or you can install them in your system's Python directory.

RedHat 6.2 users can type the following:

bash$ mkdir xmlrpclib-0.9.8
bash$ cd xmlrpclib-0.9.8
bash$ unzip ../xmlrpc-0.9.8-990621.zip
bash$ python
python> import xmlrpclib
python> import xmlrpcserver
python> Control-D
bash$ su -c 'cp *.py *.pyc /usr/lib/python1.5/'

We import two of the *.py files to trick Python into compiling them. Users of other platforms should consult their Python documentation.

For more Python examples, see the article XML-RPC: It Works Both Ways on the O'Reilly Network.

7.1. A Python Client

The following program shows how to call an XML-RPC server from Python:

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']


Comments: feedback (at) linux.org
Advertising: banners (at) linux.org
Copyright Linux Documentation Project.
Compilation ©1994-2008 Linux Online, Inc.
All rights reserved.