How to use xmlrpc in python

Source: Internet
Author: User
This article describes how to use xmlrpc in python. for details, RPC is short for Remote Procedure Call, it is a process (method) technology that calls a remote machine on a local machine. this process is also called "distributed computing ", it is a technology invented to improve the interoperability of separate machines.

The full name of the XML-RPC is XML Remote Procedure Call, that is, XML Remote method Call.

It is a set of Internet-based process calling specifications and a series of implementations that allow programs running in different operating systems and environments.
This remote procedure call uses http as the transmission protocol and XML as the encoding format for transmitting information.
The definition of Xml-Rpc is as simple as possible, but it can also transmit, process, and return complex data structures.
Python under the XML-RPC:

1. class library: xmlrpclib is generally used in the client, this module is used to call the function registered in the XML-RPC server, xmlrpclib is not a type of secure module, can not resist malicious data, some processing work in this area must be handed over to the developer himself.

2. class library: SimpleXMLRPCServer is generally used on the server side, this module is used to construct a basic XML-RPC server framework

3, construct a basic XML-RPC Server:

The code is as follows:


From SimpleXMLRPCServer import SimpleXMLRPCServer

Def is_even (n ):
Return n % 2 = 0
Server = SimpleXMLRPCServer ("localhost", 8000) # determine the URL and port
Print "Listening on port 8000 ..."
Server. register_function (is_even, "is_even") # register the is_even function
Server. serve_forever () # Start the server and make it available for this connection

4, the construction of a basic XML-RPC Client:

The code is as follows:


Import xmlrpclib
Proxy = xmlrpclib. ServerProxy ("http: // localhost: 8000 /")
Print "3 is even: % s" % str (proxy. is_even (3) # client calls the XML-RPC function
Print "100 is even: % s" % str (proxy. is_even (100 ))

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.