xmlrpclib - error marshalling new-style classes

Discussion in 'Python' started by Gabriel PASTOR, Nov 16, 2004.

  1. 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
    Gabriel PASTOR, Nov 16, 2004
    #1
    1. Advertising

  2. Gabriel PASTOR

    infidel Guest

    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".
    infidel, Nov 16, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Max Derkachev
    Replies:
    4
    Views:
    660
    Jack Diederich
    May 5, 2005
  2. ankit
    Replies:
    1
    Views:
    328
    Alex Martelli
    Dec 22, 2005
  3. Isaac Rodriguez

    Are all classes new-style classes in 2.4+?

    Isaac Rodriguez, Dec 31, 2006, in forum: Python
    Replies:
    4
    Views:
    379
    Steven D'Aprano
    Dec 31, 2006
  4. Quek
    Replies:
    3
    Views:
    323
  5. Ken Varn
    Replies:
    0
    Views:
    424
    Ken Varn
    Apr 26, 2004
Loading...

Share This Page