Python Forum

Full Version: Getting error from subprocess module
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm writing a script to log disk usage on all our hosts to a central DB server. This works fine on one host, but on a different host I'm getting an error:

Output:
# python36 Python 3.6.8 (default, Apr 25 2019, 21:02:35) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import subprocess >>> df = subprocess.run(['df','-m'], universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.6/site-packages/run/__init__.py", line 145, in __new__ process = cls.create_process(command, stdin, cwd=cwd, env=env, shell=shell) File "/usr/local/lib/python3.6/site-packages/run/__init__.py", line 121, in create_process shlex.split(command), File "/usr/lib64/python3.6/shlex.py", line 305, in split return list(lex) File "/usr/lib64/python3.6/shlex.py", line 295, in __next__ token = self.get_token() File "/usr/lib64/python3.6/shlex.py", line 105, in get_token raw = self.read_token() File "/usr/lib64/python3.6/shlex.py", line 136, in read_token nextchar = self.instream.read(1) AttributeError: 'list' object has no attribute 'read' >>>
Both hosts are running CentOS 7 and Python 3.6.8

Doing a little more investigation, I was able to replicate the problem on the first host by running pip3 install subprocess.run. I then ran pip3 uninstall subprocess.run on both hosts and was able to get things working again.

I was unaware that Python includes the subprocess.run module, but apparently the version installed with Pip is faulty? Can someone explain what happened here?
It seems that there is a package named subprocess.run in pypi. It's probably not what you want. From your error message this package doesn't support a list as the first argument of run().
(Sep-16-2019, 02:08 PM)swechsler Wrote: [ -> ]I was unaware that Python includes the subprocess.run module, but apparently the version installed with Pip is faulty? Can someone explain what happened here?
subprocess added the run() function in 3.5,not related to the 3-party PyPi module.
subprocess Wrote:The run() function was added in Python 3.5;