subprocess.check_output(input=None) raises an AttributeError when called with encoding or errors args.
Example:
>>> check_output(['ls'], input=None, encoding='utf-8')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/ak/opensource/cpython4/Lib/subprocess.py", line 466, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ak/opensource/cpython4/Lib/subprocess.py", line 549, in run
stdout, stderr = process.communicate(input, timeout=timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ak/opensource/cpython4/Lib/subprocess.py", line 1206, in communicate
stdout, stderr = self._communicate(input, endtime, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ak/opensource/cpython4/Lib/subprocess.py", line 2035, in _communicate
self._save_input(input)
File "/Users/ak/opensource/cpython4/Lib/subprocess.py", line 2115, in _save_input
self._input = self._input.encode(self.stdin.encoding,
^^^^^^^^^^^^^^^^^^
AttributeError: 'bytes' object has no attribute 'encode'. Did you mean: 'decode'?
Your environment
CPython versions tested on: 3.12 (the issue is also present in 3.10 and 3.11)
Activity
pythongh-97825: fix AttributeError when calling subprocess.check_outp…
pythongh-97825: fix AttributeError when calling subprocess.check_outp…
pythongh-97825: fix AttributeError when calling subprocess.check_outp…
gpshead commented on Oct 5, 2022
thanks! That this bug has probably been present for so long I guess means people don't use this combination of args very often?
akulakov commented on Oct 5, 2022
I think input=None maybe isn't used much, and the workaround of input='' is not too hard to find.
Thanks for reviewing @gpshead @JelleZijlstra !
gh-97825: fix AttributeError when calling subprocess.check_output(inp…
gh-97825: fix AttributeError when calling subprocess.check_output(inp…
Merge branch 'main' into dictwatch
pythongh-97825: fix AttributeError when calling subprocess.check_outp…