Install Python XMLRPC
Posted: Thu May 29, 2014 2:09 am
I'm using Raspbian and wanted to test out Python XMLRPC, however, I don't seem to have this library and cannot figure out how to install it. Any help would be greatly appreciated.
This is the sample code I was trying to run:
This is the sample code I was trying to run:
Code: Select all
from xmlrpc.server import SimpleXMLRPCServer
def hello(name='World'):
"""Return a string saying hello to the name given"""
return 'Hello, %s!' % name
def add(x, y):
"""Add two variables together and return the result"""
return x + y
# set up the server
server = SimpleXMLRPCServer(("localhost", 8000))
# register our functions
server.register_function(hello)
server.register_function(add)
# Run the server's main loop
server.serve_forever()
rpc_client.py:
import xmlrpc.client
s = xmlrpc.client.ServerProxy('http://localhost:8000')
# call the 'hello' function with no parameters
print(s.hello())
# call the 'hello' function with a name
print(s.hello('XMLRPC'))
# add two numbers together
print('2+3=%s' % s.add(2,3))