[Twisted-Python] Another silly XML-RPC question

Dave Peticolas dave at krondo.com
Tue Aug 26 00:25:28 EDT 2003


On Mon, 2003-08-25 at 20:50, Steve Freitas wrote:
> 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...

This will never work since XML-RPC doesn't support **kw arguments.


> >>> 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!

No, you just send a python dictionary. XML-RPC will serialize
it as a struct and it will be converted back to a Python dict
before it is passed to your handler.

If you're using Twisted on the client side as well:

  proxy.callRemote('foo', {'x':42})

dave

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20030825/b51c9f48/attachment.pgp 


More information about the Twisted-Python mailing list