[New-bugs-announce] [issue31178] [EASY] subprocess: TypeError: can't concat str to bytes, in _execute_child()
STINNER Victor
report at bugs.python.org
Thu Aug 10 11:29:44 EDT 2017
New submission from STINNER Victor:
Lib/subprocess.py contains the following code:
try:
exception_name, hex_errno, err_msg = (
errpipe_data.split(b':', 2))
except ValueError:
exception_name = b'SubprocessError'
hex_errno = b'0'
err_msg = (b'Bad exception data from child: ' +
repr(errpipe_data))
b'...' + repr() is wrong: it raises a "TypeError: can't concat str to bytes" when python3 is run with -bb.
Example with attached subprocess_bug.patch:
haypo at selma$ ./python -bb -m test -v test_subprocess -m test_invalid_args
(...)
======================================================================
ERROR: test_invalid_args (test.test_subprocess.ContextManagerTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/haypo/prog/python/master/Lib/subprocess.py", line 1309, in _execute_child
errpipe_data.split(b':', 1))
ValueError: not enough values to unpack (expected 3, got 2)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/haypo/prog/python/master/Lib/test/test_subprocess.py", line 2880, in test_invalid_args
stderr=subprocess.PIPE) as proc:
File "/home/haypo/prog/python/master/Lib/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/home/haypo/prog/python/master/Lib/subprocess.py", line 1314, in _execute_child
repr(errpipe_data))
TypeError: can't concat str to bytes
IMHO err_msg should be decoded using err_msg.decode(errors="surrogatepass") and then use 'Bad ...: %s' % err_msg. It would need to add an "else:" block to the try/except to do the err_msg.decode(errors="surrogatepass") when no error is raised. Well, something like that :-)
----------
components: Library (Lib)
files: subprocess_bug.patch
keywords: easy, patch
messages: 300102
nosy: haypo
priority: normal
severity: normal
status: open
title: [EASY] subprocess: TypeError: can't concat str to bytes, in _execute_child()
versions: Python 3.7
Added file: http://bugs.python.org/file47077/subprocess_bug.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue31178>
_______________________________________
More information about the New-bugs-announce
mailing list