From 8ade68dbef50f90ffabbc3d6014a164ffa3c3cf6 Mon Sep 17 00:00:00 2001 From: Konstantinos Karmas Date: Wed, 23 Jun 2021 11:20:35 +0200 Subject: [PATCH] Catch the KeyringLocked error instead of the MacOS specific Turns out that when the KeychainDenied error is raised, it is being caught by the macOS keyring api and the non-macOS-specific KeyringLocked error is raised instead, so we need to catch this one. CURA-8332 --- cura/OAuth2/KeyringAttribute.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/cura/OAuth2/KeyringAttribute.py b/cura/OAuth2/KeyringAttribute.py index 1d6f329ea9..1a522b4061 100644 --- a/cura/OAuth2/KeyringAttribute.py +++ b/cura/OAuth2/KeyringAttribute.py @@ -1,10 +1,10 @@ # Copyright (c) 2021 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. -from typing import Type, TYPE_CHECKING, Optional, List, Union +from typing import Type, TYPE_CHECKING, Optional, List import keyring from keyring.backend import KeyringBackend -from keyring.errors import NoKeyringError, PasswordSetError, KeyringError +from keyring.errors import NoKeyringError, PasswordSetError, KeyringLocked from UM.Logger import Logger @@ -14,24 +14,13 @@ if TYPE_CHECKING: # Need to do some extra workarounds on windows: import sys from UM.Platform import Platform - - -class _KeychainDenied(Exception): - pass - - if Platform.isWindows() and hasattr(sys, "frozen"): import win32timezone from keyring.backends.Windows import WinVaultKeyring keyring.set_keyring(WinVaultKeyring()) if Platform.isOSX() and hasattr(sys, "frozen"): from keyring.backends.macOS import Keyring - from keyring.backends.macOS.api import KeychainDenied as _KeychainDeniedMacOS - KeychainDenied: Union[Type[_KeychainDenied], Type[_KeychainDeniedMacOS]] = _KeychainDeniedMacOS keyring.set_keyring(Keyring()) -else: - KeychainDenied = _KeychainDenied - # Even if errors happen, we don't want this stored locally: DONT_EVER_STORE_LOCALLY: List[str] = ["refresh_token"] @@ -50,7 +39,7 @@ class KeyringAttribute: self._store_secure = False Logger.logException("w", "No keyring backend present") return getattr(instance, self._name) - except KeychainDenied: + except KeyringLocked: self._store_secure = False Logger.log("i", "Access to the keyring was denied.") return getattr(instance, self._name)