From c5cf8291175a3f35521279b4f95b9cb0b677f225 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 16 Aug 2017 09:57:57 -0400 Subject: [PATCH] Avoid stacktrace on pipe on non-ascii Various commands may (accidentally or intentionally) encounter non-ascii data. While python stdout without pipe is fine, when piping it assumes ascii. Fix this to always assume utf-8 explicitly. --- confluent_client/bin/nodeeventlog | 3 +++ confluent_client/bin/nodeinventory | 3 +++ confluent_client/bin/nodesensors | 3 +++ 3 files changed, 9 insertions(+) diff --git a/confluent_client/bin/nodeeventlog b/confluent_client/bin/nodeeventlog index b467ad28..c2b094de 100755 --- a/confluent_client/bin/nodeeventlog +++ b/confluent_client/bin/nodeeventlog @@ -15,6 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import codecs from datetime import datetime as dt import optparse import os @@ -32,6 +33,8 @@ if path.startswith('/opt'): import confluent.client as client +sys.stdout = codecs.getwriter('utf8')(sys.stdout) + argparser = optparse.OptionParser( usage="Usage: %prog [options] noderange [clear]") (options, args) = argparser.parse_args() diff --git a/confluent_client/bin/nodeinventory b/confluent_client/bin/nodeinventory index 58afcd59..be3c03c1 100755 --- a/confluent_client/bin/nodeinventory +++ b/confluent_client/bin/nodeinventory @@ -15,6 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import codecs import optparse import os import re @@ -32,6 +33,8 @@ if path.startswith('/opt'): import confluent.client as client +sys.stdout = codecs.getwriter('utf8')(sys.stdout) + filters = [] diff --git a/confluent_client/bin/nodesensors b/confluent_client/bin/nodesensors index 60e69cac..85dc0053 100755 --- a/confluent_client/bin/nodesensors +++ b/confluent_client/bin/nodesensors @@ -15,6 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import codecs import csv import datetime import optparse @@ -34,6 +35,8 @@ if path.startswith('/opt'): import confluent.client as client +sys.stdout = codecs.getwriter('utf8')(sys.stdout) + sensorcollections = { 'all': 'sensors/hardware/all/all', 'temperature': 'sensors/hardware/temperature/all',