New submission from STINNER Victor:

Lib/ contains the following code:

                    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: ' +

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@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/", line 1309, in 
    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/", line 2880, 
in test_invalid_args
    stderr=subprocess.PIPE) as proc:
  File "/home/haypo/prog/python/master/Lib/", line 709, in __init__
    restore_signals, start_new_session)
  File "/home/haypo/prog/python/master/Lib/", line 1314, in 
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 
versions: Python 3.7
Added file:

Python tracker <>
Python-bugs-list mailing list

Reply via email to