distro-tool: handle garbage in error response

This commit is contained in:
MilhouseVH 2019-05-25 13:59:07 +01:00
parent 491610dc00
commit 72cdeda49e

View File

@ -104,7 +104,13 @@ class MyUtility(object):
return (0, subprocess.check_output(command.split(" "), stderr=_logfile))
except subprocess.CalledProcessError as cpe:
if MyUtility.isPython3:
return (cpe.returncode, cpe.output.decode("utf-8"))
# Clean up undecodable garbage in response (eg. libftdi1 error page)
output = bytearray()
for c in cpe.output:
if c <= 127:
output.append(c)
return (cpe.returncode, output.decode("utf-8"))
else:
return (cpe.returncode, cpe.output)
finally: