471,305 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,305 software developers and data experts.

xmlrpclib - error marshalling new-style classes

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

Jul 18 '05 #1
1 2512
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".

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by sashan | last post: by
2 posts views Thread by p2esp | last post: by
reply views Thread by Alan Little | last post: by
3 posts views Thread by writeson | last post: by
3 posts views Thread by Rune Froysa | last post: by
reply views Thread by Willi Langenberger | last post: by
2 posts views Thread by DazedAndConfused | last post: by
reply views Thread by gregarican | last post: by
reply views Thread by Arno Stienen | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.