From 68952c20bd15f0f9f8dfaa034a13308ba5807bdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 10 Apr 2019 13:27:24 +0200 Subject: [PATCH] =?UTF-8?q?=E2=8F=AA=20Switch=20lines=20read=20from=20seri?= =?UTF-8?q?al=20back=20to=20bytes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While long term we want to have unicode here, the rest of the code is not even remotely prepared for handling utf-8 strings as visible in the large amount of unicode issues visible in sentry. So for now we go back to byte objects and fix #3091 differently --- src/octoprint/util/comm.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 4df90bf7d..8094cc705 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -2746,13 +2746,12 @@ class MachineCom(object): self.close(is_error=True) return None - try: - ret = ret.decode('utf-8').rstrip() - except UnicodeDecodeError: - ret = ret.decode('latin1').rstrip() - - if ret != u"": - self._log(u"Recv: {}".format(ret)) + if ret != "": + try: + self._log("Recv: " + sanitize_ascii(ret)) + except ValueError as e: + self._log("WARN: While reading last line: %s" % e) + self._log("Recv: " + repr(ret)) for name, hook in self._received_message_hooks.items(): try: