From 48fa74e7a907a4fa3cff3a7aec506a4bc3439ba6 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 22 Aug 2019 08:57:47 -0400 Subject: [PATCH] Explicitly use utf8 when encode error encountered Some platforms do not naturally do utf-8. This is pretty much always the answer, so try it if the default encoding of a platform fails. --- confluent_client/confluent/client.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/confluent_client/confluent/client.py b/confluent_client/confluent/client.py index bf8f15b3..ccdea68b 100644 --- a/confluent_client/confluent/client.py +++ b/confluent_client/confluent/client.py @@ -1,7 +1,7 @@ # vim: tabstop=4 shiftwidth=4 softtabstop=4 # Copyright 2014 IBM Corporation -# Copyright 2015-2018 Lenovo +# Copyright 2015-2019 Lenovo # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -107,7 +107,10 @@ def printerror(res, node=None): def cprint(txt): - print(txt) + try: + print(txt) + except UnicodeEncodeError: + print(txt.encode('utf8')) sys.stdout.flush() def _parseserver(string):