[Twisted-Python] Another silly XML-RPC question

Steve Freitas sflist at ihonk.com
Mon Aug 25 21:50:03 MDT 2003


Hi all,

This is maybe just a Python library question, but I'm not sure.

I'd like to set up an XML-RPC server function to accept a dictionary/struct. 
So I thought I'd do this...

def xmlrpc_foo(self, **mydict):

But when I send it a struct, it throws an error of '0 args expected, 1 given,' 
much like...

>>> def blah(**myDict):
>>>   return myDict['x']
>>>
>>> print blah({'x':42, 'y':3})

...does. So under regular Python, the way to make this work fine is:

>>> def blah(myDict):
>>>   return myDict['x']
>>>
>>> print blah({'x':42, 'y':3})

But when I try this under twisted...

def xmlrpc_foo(self, myDict):
        return myDict['x']

I get a key error, saying strings are not callable.

So how do I get a twisted xmlrpc function to accept a struct? I assume I have 
to take it into a string and somehow serialize it into a dictionary using 
XML-RPC magic I haven't learned about, as in...

def xmlrpc_foo(self, myDict):
        ...magically transform myDict (a string) into myNewDict (a dict!)...
        return myNewDict['x']

Any help is appreciated! Thanks!

Steve




More information about the Twisted-Python mailing list