From 3ae0296b14e2e782e6d6a469719c52c5cba7f7aa Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Wed, 17 Apr 2019 09:13:53 +0200 Subject: [PATCH] ansible-test yamllint: fix UnicodeDecodeError (#55364) * ansible-test yamllint: fix UnicodeDecodeError * Conditional fix (cherry picked from commit f8bebc61c8e176f8ebde9743a59b162d1df6ae6a) --- test/runner/lib/util.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/runner/lib/util.py b/test/runner/lib/util.py index 3ca4e04536..a8f88a8e76 100644 --- a/test/runner/lib/util.py +++ b/test/runner/lib/util.py @@ -381,7 +381,10 @@ def raw_command(cmd, capture=False, env=None, data=None, cwd=None, explain=False if communicate: encoding = 'utf-8' - data_bytes = data.encode(encoding, 'surrogateescape') if data else None + if data is None or isinstance(data, bytes): + data_bytes = data + else: + data_bytes = data.encode(encoding, 'surrogateescape') stdout_bytes, stderr_bytes = process.communicate(data_bytes) stdout_text = stdout_bytes.decode(encoding, str_errors) if stdout_bytes else u'' stderr_text = stderr_bytes.decode(encoding, str_errors) if stderr_bytes else u''