#pragma section-numbers off = XML-RPC = XML-RPC is a neat way to send messages across the Internet. The neat thing about XML-RPC is that it transports ''native data structures''- you can ship off lists, strings, dictionaries, and numbers. You can [[Wiki:XmlRpc|read more about it over on C2,]] or on [[http://www.xmlrpc.com/|the XML-RPC home page.]] == Sample Code == {{{ #!python import xmlrpclib XMLRPC_SERVER_URL = "http://www.python.org/cgi-bin/moinmoin/?action=xmlrpc" pythoninfo = xmlrpclib.ServerProxy( XMLRPC_SERVER_URL ) allpages = pythoninfo.getAllPages() # this is the XML-RPC call print ", ".join( allpages ) }}} This code calls the PythonInfo wiki, and receives the TitleIndex as a list. == Message Format == If you can communicate strings, you can do XML-RPC. You could even do it by e-mail! Here's how to make your string: {{{ #!python import xmlrpclib func_name = "foo" arg_1 = "robot" arg_2 = { "some":1, "dict":2 } arg_3 = [1,2,3,4,5] call_string = xmlrpclib.dumps( (arg_1,arg_2,arg_3,), func_name ) }}} ...resulting in the following {{{call_string}}} value: {{{ foo robot dict 2 some 1 1 2 3 4 5 }}} ...which can then be turned ''back'' into Python data: {{{ #!python call_data = xmlrpclib.loads( call_string ) }}} ...which then builds: {{{ (('robot', {'some': 1, 'dict': 2}, [1, 2, 3, 4, 5]), u'foo') }}} That is, the first item is the arguments tuple, and the second item is the name of the function. The capabilities are described under "Convenience Functions" in [[http://docs.python.org/lib/module-xmlrpclib.html|the xmlrpclib documentation.]] == See Also == * [[http://docs.python.org/lib/xmlrpc-client-example.html|official xmlrpclib example]] * [[https://docs.python.org/2/library/xmlrpclib.html|xmlrpclib documentation]] * [[http://www.onlamp.com/pub/a/python/2001/01/17/xmlrpcserver.html|XML-RPC: It Works Both Ways (onlamp.com)]] * DocXmlRpcServer - class to help make an XML-RPC server * [[http://effbot.org/zone/xmlrpc-cgi.htm|Providing XML-RPC Services via CGI]]