Skip to content

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

@Hitesh-1991

Description

@Hitesh-1991

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions