Download   Online Shop   Red Hat Network
Home  |  Products & Services  |  Support  |  Training  |  Partners  |  Documentation   
Red Hat Documentation

Overview | HOWTOs | mini-HOWTOs | FAQs | Linux Man-Pages

Using XML-RPC with Python

6. 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.

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

 

 
 
Search for:  on    Powered by Google
Products & Services   :   Download   :   Support   :   Training   :   Partners & Programs
© 2001 Red Hat, Inc. All rights reserved.       About Red Hat   :   Legal statement   :   Privacy statement   :   Y2K statement   :   Contact Red Hat