From 9043d263c7bd935474191dcf38fa5a24f60ce4a8 Mon Sep 17 00:00:00 2001 From: Xu Tian Date: Fri, 31 Mar 2017 09:37:38 +0800 Subject: [PATCH] virttest.utils_misc: fix unicode decode errors Signed-off-by: Xu Tian --- virttest/utils_misc.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/virttest/utils_misc.py b/virttest/utils_misc.py index eb62273c1c..81f3761737 100644 --- a/virttest/utils_misc.py +++ b/virttest/utils_misc.py @@ -477,10 +477,9 @@ def log_line(filename, line): pass _open_log_files[base_file] = open(log_file, "w") timestr = time.strftime("%Y-%m-%d %H:%M:%S") - _open_log_files[base_file].write("%s: %s\n" - % (timestr, - line.encode(ENCODING, - 'ignore'))) + line = unicode("%s: %s" % (timestr, line), errors="ignore") + line = line.encode(ENCODING, errors='ignore') + _open_log_files[base_file].write("%s\n" % line) _open_log_files[base_file].flush() finally: _log_lock.release()