Title: [EASY] subprocess: TypeError: can't concat str to bytes, in _execute_child()
Type: Stage:
Components: Library (Lib) Versions: Python 3.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: haypo
Priority: normal Keywords: easy, patch

Created on 2017-08-10 15:29 by haypo, last changed 2017-08-10 19:17 by ammar2.

File name Uploaded Description Edit
subprocess_bug.patch haypo, 2017-08-10 15:29
Pull Requests
URL Status Linked Edit
PR 3066 open ammar2, 2017-08-10 19:17
Messages (1)
msg300102 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2017-08-10 15:29
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 _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/", 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 _execute_child
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 :-)
Date User Action Args
2017-08-10 19:17:41ammar2setpull_requests: + pull_request3103
2017-08-10 15:29:44haypocreate