From 6e84d39cae0c2fc6af4b4efba02e3918c754814c Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Fri, 15 Jul 2016 14:14:22 +0200 Subject: [PATCH] Improved error handling of authentication --- NetworkPrinterOutputDevice.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/NetworkPrinterOutputDevice.py b/NetworkPrinterOutputDevice.py index cef661d1a2..cb1a7789ca 100644 --- a/NetworkPrinterOutputDevice.py +++ b/NetworkPrinterOutputDevice.py @@ -427,7 +427,7 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): self._requestAuthentication() elif reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) == 403: pass - else: + elif reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) == 200: self.setAuthenticationState(AuthState.Authenticated) global_container_stack = Application.getInstance().getGlobalContainerStack() ## Save authentication details. @@ -441,6 +441,10 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): else: global_container_stack.addMetaDataEntry("network_authentication_id", self._authentication_id) Logger.log("i", "Authentication succeeded") + else: # Got a response that we didn't expect, so something went wrong. + Logger.log("w", "While trying to authenticate, we got an unexpected response: %s", reply.attribute(QNetworkRequest.HttpStatusCodeAttribute)) + self.setAuthenticationState(AuthState.NotAuthenticated) + elif "auth/check" in reply.url().toString(): # Check if we are authenticated (user can refuse this!) data = json.loads(bytes(reply.readAll()).decode("utf-8")) if data.get("message", "") == "authorized":