From 1f9c440525f3518441fc4da8048e85efa2b5c443 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 22 Apr 2021 15:14:52 -0400 Subject: [PATCH] Handle non-utf8 console data Sometimes console uses non-utf8. Fallback to cp437 when utf8 fails us. --- confluent_server/confluent/httpapi.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/confluent_server/confluent/httpapi.py b/confluent_server/confluent/httpapi.py index d2d746fa..e1519787 100644 --- a/confluent_server/confluent/httpapi.py +++ b/confluent_server/confluent/httpapi.py @@ -422,9 +422,11 @@ def wsock_handler(ws): if isinstance(data, dict): data = json.dumps(data) ws.send(u'!' + data) - elif not isinstance(data, str): - ws.send(u' ' + data.decode('utf8')) else: + try: + data = data.decode('utf8') + except UnicodeDecodeError: + data = data.decode('cp437') ws.send(u' ' + data) try: if shellsession: