From 18786a1e7db4993ef96fe6ebcdd01e1b3f28bc6c Mon Sep 17 00:00:00 2001 From: Simon Edwards Date: Wed, 6 Feb 2019 12:18:32 +0100 Subject: [PATCH 1/5] Fix the default content-type for HTTP PUT requests in NetworkedPrinterOutputDevice CL-1237 --- cura/PrinterOutput/NetworkedPrinterOutputDevice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura/PrinterOutput/NetworkedPrinterOutputDevice.py b/cura/PrinterOutput/NetworkedPrinterOutputDevice.py index 47a6caf3e5..bbeb87d5e3 100644 --- a/cura/PrinterOutput/NetworkedPrinterOutputDevice.py +++ b/cura/PrinterOutput/NetworkedPrinterOutputDevice.py @@ -199,7 +199,7 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice): # \param content_type: The content type of the body data. # \param on_finished: The function to call when the response is received. # \param on_progress: The function to call when the progress changes. Parameters are bytes_sent / bytes_total. - def put(self, url: str, data: Union[str, bytes], content_type: Optional[str] = None, + def put(self, url: str, data: Union[str, bytes], content_type: Optional[str] = "application/json", on_finished: Optional[Callable[[QNetworkReply], None]] = None, on_progress: Optional[Callable[[int, int], None]] = None) -> None: self._validateManager() From 8e569126ff435e6e9a375e041ba6ec974258add0 Mon Sep 17 00:00:00 2001 From: Simon Edwards Date: Wed, 6 Feb 2019 12:19:59 +0100 Subject: [PATCH 2/5] Use the older but backwards compatible API for moving print jobs in the queue. CL-1237 --- plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py b/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py index e2215c85e7..052dd0b979 100644 --- a/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py +++ b/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py @@ -355,8 +355,8 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice): def sendJobToTop(self, print_job_uuid: str) -> None: # This function is part of the output device (and not of the printjob output model) as this type of operation # is a modification of the cluster queue and not of the actual job. - data = "{\"list\": \"queued\",\"to_position\": 0}" - self.post("print_jobs/{uuid}/action/move".format(uuid = print_job_uuid), data, on_finished=None) + data = "{\"to_position\": 0}" + self.put("print_jobs/{uuid}/move_to_position".format(uuid = print_job_uuid), data, on_finished=None) @pyqtSlot(str) def deleteJobFromQueue(self, print_job_uuid: str) -> None: From 19f1a2f2d047f646c227e3fbb0d74f2cb7d57abd Mon Sep 17 00:00:00 2001 From: Ian Paschal Date: Fri, 8 Feb 2019 09:23:38 +0100 Subject: [PATCH 3/5] Fix line length Contributes to CL-1237 --- plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py b/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py index 052dd0b979..866d62ad52 100644 --- a/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py +++ b/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py @@ -356,7 +356,10 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice): # This function is part of the output device (and not of the printjob output model) as this type of operation # is a modification of the cluster queue and not of the actual job. data = "{\"to_position\": 0}" - self.put("print_jobs/{uuid}/move_to_position".format(uuid = print_job_uuid), data, on_finished=None) + self.put( + "print_jobs/{uuid}/move_to_position".format( uuid = print_job_uuid), + data, + on_finished=None) @pyqtSlot(str) def deleteJobFromQueue(self, print_job_uuid: str) -> None: From 729f4c9d52975c2503a22dfa69e7b4585cfb6488 Mon Sep 17 00:00:00 2001 From: Ian Paschal Date: Fri, 8 Feb 2019 09:40:56 +0100 Subject: [PATCH 4/5] Revert "Fix line length" This reverts commit 19f1a2f2d047f646c227e3fbb0d74f2cb7d57abd. --- plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py b/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py index 866d62ad52..052dd0b979 100644 --- a/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py +++ b/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py @@ -356,10 +356,7 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice): # This function is part of the output device (and not of the printjob output model) as this type of operation # is a modification of the cluster queue and not of the actual job. data = "{\"to_position\": 0}" - self.put( - "print_jobs/{uuid}/move_to_position".format( uuid = print_job_uuid), - data, - on_finished=None) + self.put("print_jobs/{uuid}/move_to_position".format(uuid = print_job_uuid), data, on_finished=None) @pyqtSlot(str) def deleteJobFromQueue(self, print_job_uuid: str) -> None: From 91f0d76c8a4d6affecb1f41529b138ccf1fb051d Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Fri, 8 Feb 2019 10:50:17 +0100 Subject: [PATCH 5/5] Fix crash when user was logged in but there was no internet connection on boot --- cura/OAuth2/AuthorizationHelpers.py | 2 +- cura/OAuth2/AuthorizationService.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cura/OAuth2/AuthorizationHelpers.py b/cura/OAuth2/AuthorizationHelpers.py index 762d0db069..87b8c45d6d 100644 --- a/cura/OAuth2/AuthorizationHelpers.py +++ b/cura/OAuth2/AuthorizationHelpers.py @@ -85,7 +85,7 @@ class AuthorizationHelpers: token_request = requests.get("{}/check-token".format(self._settings.OAUTH_SERVER_URL), headers = { "Authorization": "Bearer {}".format(access_token) }) - except ConnectionError: + except requests.exceptions.ConnectionError: # Connection was suddenly dropped. Nothing we can do about that. Logger.logException("e", "Something failed while attempting to parse the JWT token") return None diff --git a/cura/OAuth2/AuthorizationService.py b/cura/OAuth2/AuthorizationService.py index 1e98dc9cee..fc004e5e0d 100644 --- a/cura/OAuth2/AuthorizationService.py +++ b/cura/OAuth2/AuthorizationService.py @@ -4,6 +4,8 @@ import json import webbrowser from typing import Optional, TYPE_CHECKING from urllib.parse import urlencode +import requests.exceptions + from UM.Logger import Logger from UM.Signal import Signal @@ -51,7 +53,11 @@ class AuthorizationService: def getUserProfile(self) -> Optional["UserProfile"]: if not self._user_profile: # If no user profile was stored locally, we try to get it from JWT. - self._user_profile = self._parseJWT() + try: + self._user_profile = self._parseJWT() + except requests.exceptions.ConnectionError: + # Unable to get connection, can't login. + return None if not self._user_profile and self._auth_data: # If there is still no user profile from the JWT, we have to log in again.