Question

I've got a Pyro4 daemon going which I would like to have return a connection to LDAP (instantiated by the python-ldap module). The code is short and simple, but I run into an error with (I believe) serialization of the connection object upon my attempt to return the connection to the client script.

class LDAPDaemon(object):
   def get_ldap_connection(self):
      conn = ldap.initialize("ldap://ds1")
      conn.simple_bind_s("cn=Directory Manager", "abc123")
      return conn

daemon = Pyro4.Daemon(unixsocket="/tmp/ldap_unix.sock")
os.system("chmod 700 /tmp/ldap_unix.sock")
uri=daemon.register(LDAPDaemon(), "LDAPDaemon")
daemon.requestLoop()

Then in my driver script, I have the following (assume uri is known, cut all that out for brevity's sake):

with Pyro4.Proxy(uri) as ldap_daemon:
   conn = ldap_daemon.get_ldap_connection()

This results in the following error:

Traceback (most recent call last):
  File "./tester.py", line 14, in <module>
    conn = ldap_daemon.get_ldap_connection()
  File "/opt/csw/lib/python2.6/site-packages/Pyro4/core.py", line 160, in __call__
    return self.__send(self.__name, args, kwargs)
  File "/opt/csw/lib/python2.6/site-packages/Pyro4/core.py", line 318, in _pyroInvoke
    raise data
AttributeError: __class__

I tried changing the Pyro4 configuration to accept different serializers, i.e.:

Pyro4.config.SERIALIZERS_ACCEPTED = set(['json', 'marshal', 'serpent', 'pickle'])

but that didn't change anything.

Please ignore the glaring security holes as this was dumbed down to the most basic code to produce the error.

Was it helpful?

Solution

You guessed right. The LDAPOject is not serializable. Arguments passed to a remote object and the return values of its methods are serialized and then sent through a socket. Not serializable objects will cause errors. You should consider User's comment, create a proxy for the connection instead of sending it to the other process or you have to find a way to serialize it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top