From eb99aa8c68ba452f4f1545e2079461f9737345d1 Mon Sep 17 00:00:00 2001 From: Marius Gedminas Date: Thu, 27 Aug 2015 09:38:12 +0300 Subject: [PATCH] Fix to_bytes(None) on Python 3 You cannot call bytes(obj) to get a simple representation of obj on Python 3! E.g. bytes(42) returns a byte string with 42 NUL characters instead of b'42'. --- lib/ansible/utils/unicode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/utils/unicode.py b/lib/ansible/utils/unicode.py index 2cff2e5e45..a63c1960e1 100644 --- a/lib/ansible/utils/unicode.py +++ b/lib/ansible/utils/unicode.py @@ -215,7 +215,7 @@ def to_bytes(obj, encoding='utf-8', errors='replace', nonstring=None): return obj elif nonstring == 'simplerepr': try: - simple = binary_type(obj) + simple = str(obj) except UnicodeError: try: simple = obj.__str__()