Reputation: 169
I have a simple example to send a dictionary through xml-rpc:
class CTest(object):
def __init__(self):
self.node1 = {'data':'zek', 'parent':{}, 'children':[]}
self.node2 = {'data':'bill', 'parent':{}, 'children':[]}
self.node1['children'].append(self.node2)
self.node2['parent'] = self.node1
def getNode(self):
return self.node1
I have two dictionaries: node2 is the children of node1, and in the same time node2 has the reference of node1 as parent variable. So it is a recursive dictionary. When I try to send node1 through XML-RPC, I got this exception:
#Command to execute xml-rpc dump method for serialization
test = CTest()
xmlrpclib.dumps((test,), 'Node Object')
#Exception
raise TypeError, "cannot marshal recursive dictionaries"
Is it possible to send node1 through XML-RPC (without changing dictionary structure)?
Thanks.
Upvotes: 5
Views: 3390
Reputation:
Serialize and deserialize 'test' yourself by using the 'pickle' module of Python.
cPickle.dumps(test)
is working. On the other side of the wire you use
cPickle.loads(received_test_pickle)
It might be necessary to base-64 encode/decode the pickle before/after the XMLRPC call.
But also look into PyRo
Upvotes: 5