[Twisted-Python] Another silly XML-RPC question
![](https://secure.gravatar.com/avatar/3c4988f83703127d279406fc6eea7079.jpg?s=120&d=mm&r=g)
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...
...does. So under regular Python, the way to make this work fine is:
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
![](https://secure.gravatar.com/avatar/fcc237fd34a8e504f7224df0c58cc0b3.jpg?s=120&d=mm&r=g)
On Mon, 2003-08-25 at 20:50, Steve Freitas wrote:
This will never work since XML-RPC doesn't support **kw arguments.
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
![](https://secure.gravatar.com/avatar/fd0d8d85c2a9b164931b22235045e64e.jpg?s=120&d=mm&r=g)
Dave Peticolas wrote:
On Mon, 2003-08-25 at 20:50, Steve Freitas wrote:
Or you can use objects instead of structs, jelly them, and send the jellied objects over xmlrpc -- xmlrpc has no problem with nested lists, which is what jelly produces. Good ol' jelly! Caveat: the objects' attributes have to be jellyable (some types aren't). This is analogous to the PB "copyable" paradigm. - Steve.
![](https://secure.gravatar.com/avatar/3c4988f83703127d279406fc6eea7079.jpg?s=120&d=mm&r=g)
Hi Dave, Thanks for your reply!
Unfortunately I'm using C++ on the client side, with XmlRpc++ as my library (http://xmlrpcpp.sourceforge.net/). I'd like to avoid putting Python in that mix, as I wasn't planning on using it on the client at all. Besides, I thought this was what I was doing when I sent my Twisted server a simple struct. If XML-RPC serializes it as a struct (which was what I was sending), what am I doing wrong to prevent it from working as you describe? Thanks! Steve
![](https://secure.gravatar.com/avatar/fcc237fd34a8e504f7224df0c58cc0b3.jpg?s=120&d=mm&r=g)
On Tue, 2003-08-26 at 13:51, Steve Freitas wrote:
A struct should be unserialized to a Python dict no problem. It's hard to say from here what is going on, but Twisted's XMLRPC class is so simple it should be easy to add a few print statements to find out what is happening. Check out the XMLRPC.render(...) function. You might want to print the request content and unserialized arguments as a starting point. dave
![](https://secure.gravatar.com/avatar/fcc237fd34a8e504f7224df0c58cc0b3.jpg?s=120&d=mm&r=g)
On Mon, 2003-08-25 at 20:50, Steve Freitas wrote:
This will never work since XML-RPC doesn't support **kw arguments.
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
![](https://secure.gravatar.com/avatar/fd0d8d85c2a9b164931b22235045e64e.jpg?s=120&d=mm&r=g)
Dave Peticolas wrote:
On Mon, 2003-08-25 at 20:50, Steve Freitas wrote:
Or you can use objects instead of structs, jelly them, and send the jellied objects over xmlrpc -- xmlrpc has no problem with nested lists, which is what jelly produces. Good ol' jelly! Caveat: the objects' attributes have to be jellyable (some types aren't). This is analogous to the PB "copyable" paradigm. - Steve.
![](https://secure.gravatar.com/avatar/3c4988f83703127d279406fc6eea7079.jpg?s=120&d=mm&r=g)
Hi Dave, Thanks for your reply!
Unfortunately I'm using C++ on the client side, with XmlRpc++ as my library (http://xmlrpcpp.sourceforge.net/). I'd like to avoid putting Python in that mix, as I wasn't planning on using it on the client at all. Besides, I thought this was what I was doing when I sent my Twisted server a simple struct. If XML-RPC serializes it as a struct (which was what I was sending), what am I doing wrong to prevent it from working as you describe? Thanks! Steve
![](https://secure.gravatar.com/avatar/fcc237fd34a8e504f7224df0c58cc0b3.jpg?s=120&d=mm&r=g)
On Tue, 2003-08-26 at 13:51, Steve Freitas wrote:
A struct should be unserialized to a Python dict no problem. It's hard to say from here what is going on, but Twisted's XMLRPC class is so simple it should be easy to add a few print statements to find out what is happening. Check out the XMLRPC.render(...) function. You might want to print the request content and unserialized arguments as a starting point. dave
participants (3)
-
Dave Peticolas
-
Steve Freitas
-
Steve Waterbury