xmlrpclib - error marshalling new-style classes

G

Gabriel PASTOR

I'm trying to send object using xmlrpclib, but it seems that classes inheriting from object cannot be marshalled. Here is an example:

-------- server.py --------
import xmlrpclib, SimpleXMLRPCServer

class MyObject(object):
def __init__(self,name):
self._name=name

def getMyObject(name):
obj = MyObject(name)
return obj

if __name__ == "__main__":
server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8888))
print 'server running on port 8888'
server.register_function(getMyObject)
server.handle_request()

---- client.py ------
import xmlrpclib, SimpleXMLRPCServer
server = xmlrpclib.ServerProxy("http://localhost:8888")
obj = server.getMyObject('john')
print obj

I get the following error
xmlrpclib.Fault: <Fault 1: "exceptions.TypeError:cannot marshal <class '__main__
..MyObject'> objects">

And if the class MyObject doesn't inherit from object then the program runs correctly. I have this problem using python 2.3 and the problem is exacltly the same with python 2.4 beta1

Am I doing something wrong or is it a bug in xmlrpclib ?

Regards,

gp
 
I

infidel

The XML-RPC protocol only "understands" a specific set of "types".
Basically they amount to numbers, strings, dates, arrays (lists/tuples)
and structs (dicts) containing such items. xmlrpclib has no way of
knowing how to map your class to such primitive types and reconstruct
it on the "other side".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top