开发者

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.


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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜