在rpyc中传递对象失败

Ben*_*Ben 5 python parameter-passing pass-by-reference rpyc

我正在尝试使用RPyC从客户端到服务器将对象作为参数传递.但服务器无法访问该对象,我收到一个AttributeError.

服务器代码:

class AgentService(rpyc.Service):
  def exposed_func(self, obj):
    return obj.name
Run Code Online (Sandbox Code Playgroud)

客户代码

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

returns: AttributeError: cannot access 'name'.

我正在使用RPyC服务并对网站进行评估,这应该可行.

有任何想法吗?

Ben*_*Ben 5

需要在客户端和服务器端调整config dict.

要改变的主要价值是,allow_public_attrs : True是否只需要访问公共变量,或者allow_all_attrs : True是否需要访问私有和受保护的变量和方法(即以'_'开头的那些).

在客户端,连接代码按上述问题和服务器代码编写,如下所示:

server = ThreadedServer(MyService, port = 12345,
                        protocol_config = {"allow_public_attrs" : True})
Run Code Online (Sandbox Code Playgroud)

有关所有可用配置选项的更多信息,请参阅:

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