From d42e1556e3dc67899bb2c3d3ce61dbc23ebd8fdb Mon Sep 17 00:00:00 2001 From: Nathan Hawes Date: Wed, 12 Jun 2019 12:05:15 -0700 Subject: [PATCH] [run_sk_stress_test] Replace non-ascii characters when outputting to an ascii tty Hopefully fixes the below error in the stress tester CI jobs: UnicodeEncodeError: 'ascii' codec can't encode character u'\xa9' in position 2673: ordinal not in range(128) --- run_sk_stress_test | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/run_sk_stress_test b/run_sk_stress_test index b37851e1..2172af73 100755 --- a/run_sk_stress_test +++ b/run_sk_stress_test @@ -21,6 +21,7 @@ import json import subprocess import argparse import platform +import codecs import common @@ -337,6 +338,14 @@ class StressTesterRunner(object): except OSError: pass +if os.isatty(sys.stdout.fileno()): + encoding = sys.stdout.encoding + errors = 'replace' +else: + encoding = 'utf-8' + errors = None +sys.stdout = codecs.getwriter(encoding)(sys.stdout, errors=errors) + if __name__ == '__main__': sys.exit(main())