Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML-RPC - cannot marshal recursive dictionaries

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.

like image 300
zekifh Avatar asked May 23 '11 16:05

zekifh


1 Answers

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

http://pyro.sourceforge.net/

like image 145
Andreas Jung Avatar answered Nov 01 '22 23:11

Andreas Jung