mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-19 04:09:40 +08:00
Prevent crashing on PermissionError when importing http.server (#7095)
* Fix PermissionError when importing http.server Instead of crashing, now it'll just not start the server. This means that you won't be able to receive the response from the log-in so you won't be able to log in. The browser gives an error that it can't find the page on localhost. But at least it doesn't crash. Fixes crash CURA-3Q. * Log an error when the HTTP server can't be started Contributes to crash CURA-3Q. * Indicate that types are optional Attempt to fix the typing issue with MyPy. I can't run this locally so the CI server will have to tell me if this fixed it. Contributes to Sentry issue CURA-3Q.
This commit is contained in:
parent
769fc8fd37
commit
e52dc56a64
@ -1,13 +1,18 @@
|
||||
# Copyright (c) 2019 Ultimaker B.V.
|
||||
# Copyright (c) 2020 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
import threading
|
||||
from typing import Optional, Callable, Any, TYPE_CHECKING
|
||||
from typing import Any, Callable, Optional, TYPE_CHECKING
|
||||
|
||||
from UM.Logger import Logger
|
||||
|
||||
from cura.OAuth2.AuthorizationRequestServer import AuthorizationRequestServer
|
||||
from cura.OAuth2.AuthorizationRequestHandler import AuthorizationRequestHandler
|
||||
got_server_type = False
|
||||
try:
|
||||
from cura.OAuth2.AuthorizationRequestServer import AuthorizationRequestServer
|
||||
from cura.OAuth2.AuthorizationRequestHandler import AuthorizationRequestHandler
|
||||
got_server_type = True
|
||||
except PermissionError: # Bug in http.server: Can't access MIME types. This will prevent the user from logging in. See Sentry bug Cura-3Q.
|
||||
Logger.error("Can't start a server due to a PermissionError when starting the http.server.")
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from cura.OAuth2.Models import AuthenticationResponse
|
||||
@ -50,6 +55,7 @@ class LocalAuthorizationServer:
|
||||
Logger.log("d", "Starting local web server to handle authorization callback on port %s", self._web_server_port)
|
||||
|
||||
# Create the server and inject the callback and code.
|
||||
if got_server_type:
|
||||
self._web_server = AuthorizationRequestServer(("0.0.0.0", self._web_server_port), AuthorizationRequestHandler)
|
||||
self._web_server.setAuthorizationHelpers(self._auth_helpers)
|
||||
self._web_server.setAuthorizationCallback(self._auth_state_changed_callback)
|
||||
|
Loading…
x
Reference in New Issue
Block a user