Domanda

I am trying to pass an object as a paramater using RPyC from the client to the server. But the server is unable to access the object and I receive an AttributeError.

Server Code:

class AgentService(rpyc.Service):
  def exposed_func(self, obj):
    return obj.name

client code

self._conn = connect(agent_host, agent_port, config = {"allow_public_attrs" : True})
return self._conn.root.func(obj)

returns: AttributeError: cannot access 'name'.

I am using RPyC services and accoding to the website, this should work.

Any ideas?

È stato utile?

Soluzione

The config dict needs to be adjusted on the client side and the server side.

The main value to change is allow_public_attrs : True if only public variables need to be accessed or allow_all_attrs : True if private and protected variables and methods need to be accessed (i.e, those that start with '_').

On the client side, the connection code is written as in the question above and on the server code as follows:

server = ThreadedServer(MyService, port = 12345,
                        protocol_config = {"allow_public_attrs" : True})

For more information on all the available config options, see:

http://rpyc.sourceforge.net/api/core_protocol.html

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top