Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remote subprocess module failed to execute command when client connected with ClassicClient or MasterService #565

Open
Hitesh-1991 opened this issue Nov 7, 2024 · 0 comments

Comments

@Hitesh-1991
Copy link

I wanted to connect to slave service server with client service as MasterService/ClassicClient to avoid serving as slave to server. With this client connection, I am facing below error while executing command on remote server using subprocess.run with env={}

conn.modules.subprocess.run("ls", shell=True, timeout=10, capture_output=True) --> Working
conn.modules.subprocess.run("ls", shell=True, timeout=10, capture_output=True, env={}) --> Through exception as below

stack trace / error log

conn.modules.subprocess.run("ls", shell=True, timeout=10, capture_output=True, env={})
Traceback (most recent call last):
File "", line 1, in
File "/colossus/.local/lib/python3.10/site-packages/rpyc/core/netref.py", line 239, in call
return syncreq(_self, consts.HANDLE_CALL, args, kwargs)
File "/colossus/.local/lib/python3.10/site-packages/rpyc/core/netref.py", line 63, in syncreq
return conn.sync_request(handler, proxy, *args)
File "/colossus/.local/lib/python3.10/site-packages/rpyc/core/protocol.py", line 744, in sync_request
return async_res.value
File "/colossus/.local/lib/python3.10/site-packages/rpyc/core/async
.py", line 111, in value
raise self._obj
_get_exception_class..Derived: cannot access 'items'

========= Remote Traceback (2) =========
Traceback (most recent call last):
File "/colossus/.local/lib/python3.10/site-packages/rpyc/core/protocol.py", line 369, in _dispatch_request
res = self._HANDLERS[handler](self, *args)
File "/colossus/.local/lib/python3.10/site-packages/rpyc/core/protocol.py", line 863, in _handle_call
return obj(*args, **dict(kwargs))
File "/usr/lib/python3.10/subprocess.py", line 503, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.10/subprocess.py", line 971, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.10/subprocess.py", line 1779, in _execute_child
for k, v in env.items():
File "/colossus/.local/lib/python3.10/site-packages/rpyc/core/netref.py", line 152, in getattr
return syncreq(self, consts.HANDLE_GETATTR, name)
File "/colossus/.local/lib/python3.10/site-packages/rpyc/core/netref.py", line 63, in syncreq
return conn.sync_request(handler, proxy, *args)
File "/colossus/.local/lib/python3.10/site-packages/rpyc/core/protocol.py", line 744, in sync_request
return async_res.value
File "/colossus/.local/lib/python3.10/site-packages/rpyc/core/async
.py", line 111, in value
raise self._obj
_get_exception_class..Derived: cannot access 'items'

========= Remote Traceback (1) =========
Traceback (most recent call last):
File "/colossus/.local/lib/python3.10/site-packages/rpyc/core/protocol.py", line 369, in _dispatch_request
res = self._HANDLERS[handler](self, *args)
File "/colossus/.local/lib/python3.10/site-packages/rpyc/core/protocol.py", line 879, in _handle_getattr
return self._access_attr(obj, name, (), "_rpyc_getattr", "allow_getattr", getattr)
File "/colossus/.local/lib/python3.10/site-packages/rpyc/core/protocol.py", line 806, in _access_attr
name = self._check_attr(obj, name, param)
File "/colossus/.local/lib/python3.10/site-packages/rpyc/core/protocol.py", line 796, in _check_attr
raise AttributeError(f"cannot access {name!r}")
AttributeError: cannot access 'items'

Environment
  • rpyc version - 6.0.1
  • python version - 3.10
  • operating system - Ubuntu-22
Minimal example

Server:

import rpyc
class CustomService(rpyc.SlaveService):
    pass

if __name__ == "__main__":
    from rpyc.utils.server import ThreadedServer
    server = ThreadedServer(CustomService, port=18861)
    server.start()

Client:

>>> import rpyc
>>> from rpyc.utils import factory
>>> from rpyc.core.service import ClassicClient
>>> conn = factory.connect("localhost", 18861, ClassicClient)
>>> conn.modules.subprocess.run("ls", shell=True, timeout=10, capture_output=True) --> Working 
>>> conn.modules.subprocess.run("ls", shell=True, timeout=10, capture_output=True, env={}) --> Through exception as mention above
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant