From 10f5af82f96e1482d800d8db7416cf35d46b863b Mon Sep 17 00:00:00 2001 From: cavassin Date: Thu, 5 Dec 2013 13:17:57 -0200 Subject: [PATCH] Prevent UnicodeEncodeError Prevents UnicodeEncodeError: 'ascii' codec can't encode character, while printing shell commands output --- lib/ansible/callbacks.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/ansible/callbacks.py b/lib/ansible/callbacks.py index 08da6630fb3..5274a6f8a54 100644 --- a/lib/ansible/callbacks.py +++ b/lib/ansible/callbacks.py @@ -128,9 +128,15 @@ def display(msg, color=None, stderr=False, screen_only=False, log_only=False, ru msg2 = stringc(msg, color) if not log_only: if not stderr: - print msg2 + try: + print msg2 + except UnicodeEncodeError: + print msg2.encode('utf-8') else: - print >>sys.stderr, msg2 + try: + print >>sys.stderr, msg2 + except UnicodeEncodeError: + print >>sys.stderr, msg2.encode('utf-8') if constants.DEFAULT_LOG_PATH != '': while msg.startswith("\n"): msg = msg.replace("\n","")