yes, it's a problem i get quite a lot -- you'll need to change the default
configuration. add a config dict like so:
ThreadedServer(MyService, port = 18861, config = {"allow_public_attrs" :
True, "allow_all_attrs" : True})by default, for security reasons, rpyc blocks all attribute access except for exposed and safe attrs. see http://rpyc.wikidot.com/api:core for more info. anyway, do keep in mind though that if your module (call it `foo`) imports `sys` for instance, than you can write `foo.sys`, and even `foo.sys.modules` and then gain access to all of the imported modules -- which is not safe. so it would be better to explicitly state the attrs you wish to grant access to. you can also implement _rpyc_getattr(self, name) in your service class, which is called by rpyc to get the attribute. you can refer to https://github.com/tomerfiliba/rpyc/blob/master/rpyc/core/service.py -tomer An NCO and a Gentleman On Thu, Jul 14, 2011 at 16:06, Nate <[email protected]> wrote: > Hello all, > > First off, most righteous project - I was originally going to try to > use twisted.spread until I found out about rpyc - much simpler! > > My question is simple - how, using rpyc.Service, do I expose a single > module on my server? > > Right now, this is what I'm trying: > > ######################## > import rpyc > import mymodule > class MyService(rpyc.Service): > exposed_mymodule = mymodule > > if __name__ == '__main__': > from rpyc.utils.server import ThreadedServer > t = ThreadedServer(MyService, port = 18861) > t.start() > ######################## > > Just running a test client interactively, I get this: > > >>> c = rpyc.connect_by_service("My") > >>> c.root.mymodule > <module 'mymodule' from 'C:\....\mymodule.pyc'> > >>> c.root.mymodule.multiply(2,2) > ======= Remote traceback ======= > Traceback (most recent call last): > File "C:\Python27\lib\site-packages\rpyc\core\protocol.py", line > 227, in _dispatch_request > res = self._HANDLERS[handler](self, *args) > File "C:\Python27\lib\site-packages\rpyc\core\protocol.py", line > 439, in _handle_getattr > return self._access_attr(oid, name, (), "_rpyc_getattr", > "allow_getattr", getattr) > File "C:\Python27\lib\site-packages\rpyc\core\protocol.py", line > 402, in _access_attr > raise AttributeError("cannot access %r" % (name,)) > AttributeError: cannot access 'multiply' > > ======= Local exception ======== > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "C:\Python27\lib\site-packages\rpyc\core\netref.py", line 93, > in __getattr__ > return syncreq(self, consts.HANDLE_GETATTR, name) > File "C:\Python27\lib\site-packages\rpyc\core\netref.py", line 42, > in syncreq > return conn().sync_request(handler, oid, *args) > File "C:\Python27\lib\site-packages\rpyc\core\protocol.py", line > 347, in sync_request > raise obj > AttributeError: cannot access 'multiply' > > So, how do I run a server that exposes an entire module, without > having to individually expose each method in the module? I tried > looking at SlaveService, but somehow I think that's not the way I'm > meant to do this... so any help would be appreciated!
