From 0d6ec4e693706fe5c91642164f1744bf8120ad8d Mon Sep 17 00:00:00 2001 From: Dennis Dmitriev Date: Thu, 1 Dec 2016 01:10:45 +0200 Subject: [PATCH] Set default python encoding to utf-8 To avoid unicode encoding errors [1], let's set encoding to utf-8 for the session. [1] UnicodeEncodeError: 'ascii' codec can't encode character u'\u2018' in position 11: ordinal not in range(128) Change-Id: I9b9a0c232fb8a3a3e6e851932c5e5f9a3cd7cf34 --- devops/settings.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/devops/settings.py b/devops/settings.py index ddac8b4d..add1df2d 100644 --- a/devops/settings.py +++ b/devops/settings.py @@ -12,7 +12,13 @@ # License for the specific language governing permissions and limitations # under the License. +import codecs import os +import sys + +# Set default io encoding +sys.stdout = codecs.getwriter('utf8')(sys.stdout) +sys.stderr = codecs.getwriter('utf8')(sys.stderr) _boolean_states = {'1': True, 'yes': True, 'true': True, 'on': True, '0': False, 'no': False, 'false': False, 'off': False}