From df88772071d5586d783d662679578363995816c8 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Mon, 21 Aug 2017 00:57:25 +0200 Subject: [PATCH] Add input checking for incorrect responses from printers We should not crash when getting invalid data. Just put a warning in the log there and ignore the message for the rest. --- .../NetworkPrinterOutputDevicePlugin.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevicePlugin.py b/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevicePlugin.py index 9f450f21ab..5f2ed1badc 100644 --- a/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevicePlugin.py +++ b/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevicePlugin.py @@ -117,7 +117,14 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin): if reply.operation() == QNetworkAccessManager.GetOperation: if "system" in reply_url: # Name returned from printer. if status_code == 200: - system_info = json.loads(bytes(reply.readAll()).decode("utf-8")) + try: + system_info = json.loads(bytes(reply.readAll()).decode("utf-8")) + except json.JSONDecodeError: + Logger.log("e", "Printer returned invalid JSON.") + return + except UnicodeDecodeError: + Logger.log("e", "Printer returned incorrect UTF-8.") + return address = reply.url().host() instance_name = "manual:%s" % address