XML-RPC - Python

XML-RPC is a specification and a set of implementations that allow software running on different operating systems and different environments to make procedure calls over the Internet. As a simple RPC protocol, it converts simple data types into an XML-based format, and then ships them over the network using HTTP POST requests as the transport and XML as the encoding. The procedure executes on the server and the value it returns is also formatted in XML. Procedure parameters can be scalars, numbers, strings, dates, and so on; they can also be complex record and list structures.

XML-RPC is designed to be as simple as possible, while allowing complex data structures to be transmitted, processed, and returned. This re-use of high -level ideas such as XML and HTTP makes it inefficient in comparison to a binary format, but it also makes it easy to implement; implementations already exist for Java, Python, Perl, and Tcl, and Zope 2.0.

The XML-RPC library is copyrighted, but can be used without fee. This also applies to commercial applications.

The Python implementation

PythonWare's Fredrik Lundhs xmlrpc package provides everything you need to build clients and servers in Python:

Secret Labs' xmlrpclib module is a client -side implementation of the XML -RPC protocol. This implementation is tightly integrated with Python, which makes it very easy to call remote methods. Forexample, here's the Python code needed to call one of Userland's sample servers:

betty = Serverprint betty.examples.getStateName(41)

This results in a remote call to the examples.get State Name method published by the betty server, with the integer 41 as the single argument. The result from this call is a string with the value "South Dakota". The marshalling and parsing classes provided by this module can also be used in XML-RPC server implementations. Sample code for Medusa and Python's SocketServer module is also included in the current release.

Working with Zope

Amos Latteier at Digital Creations has written an XML-RPC How To for Zope Users. Among other things, it contains code to handle authentication issues and access control.

The idea of using Zope to handle XML -RPC is based on the fact that every Zope object can respond to HTTP requests. The How To covers the use of Zope as an XML -RPC server, and as an XML-RPC client. The document also shows how to extend Fredrik Lundh's XML -RPC Python module to support sending requests with basic authentication.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Python Topics