Keyword args to SimpleXMLRPCServer

Sean DiZazzo half.italian at gmail.com
Mon Dec 17 19:13:32 EST 2007


Why is the following not working?  Is there any way to get keyword
arguments working with exposed XMLRPC functions?

~~~~~~~~~~~~~~~~ server.py
import SocketServer
from SimpleXMLRPCServer import
SimpleXMLRPCServer,SimpleXMLRPCRequestHandler

# Threaded mix-in
class
AsyncXMLRPCServer(SocketServer.ThreadingMixIn,SimpleXMLRPCServer):
pass

class XMLFunctions(object):
    def returnArgs(*args, **kwargs):
        return kwargs.items()

# Instantiate and bind to localhost:1234
server = AsyncXMLRPCServer(('', 8080), SimpleXMLRPCRequestHandler)

# Register example object instance
server.register_instance(XMLFunctions())

# run!
server.serve_forever()

~~~~~~~~~~~~~~~~ client.py
from xmlrpclib import ServerProxy, Error

server = ServerProxy("http://localhost:8080", allow_none=1) # local
server

try:
    print server.returnArgs("foo", bar="bar", baz="baz")
except Error, v:
    print "ERROR", v


[seans-imac:~/Desktop/] halfitalian% ./client.py
Traceback (most recent call last):
  File "./XMLRPC_client.py", line 9, in <module>
    print server.returnArgs("foo", bar="bar", baz="baz")
TypeError: __call__() got an unexpected keyword argument 'bar'

~Sean



More information about the Python-list mailing list