diff --git a/src/octoprint/cli/server.py b/src/octoprint/cli/server.py index eff6f5c19..2788cd5fc 100644 --- a/src/octoprint/cli/server.py +++ b/src/octoprint/cli/server.py @@ -143,7 +143,7 @@ def run_server( method("There was a fatal error starting up OctoPrint.") else: - from octoprint.server import Server + from octoprint.server import CannotStartServerException, Server octoprint_server = Server( settings=settings, @@ -159,7 +159,16 @@ def run_server( allow_root=allow_root, octoprint_daemon=octoprint_daemon, ) - octoprint_server.run() + + try: + octoprint_server.run() + except CannotStartServerException as e: + logger = logging.getLogger("octoprint.startup").fatal + echo = lambda x: click.echo(x, err=True) + + for method in logger, echo: + method(str(e)) + method("There was a fatal error starting up OctoPrint.") # ~~ server options diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index d4bbdad90..cce79ca2e 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -2441,9 +2441,25 @@ class Server(object): try: self._intermediary_server.server_bind() self._intermediary_server.server_activate() - except Exception: + except Exception as exc: self._intermediary_server.server_close() - raise + + if isinstance(exc, UnicodeDecodeError) and sys.platform == "win32": + # we end up here if the hostname contains non-ASCII characters due to + # https://bugs.python.org/issue26227 - tell the user they need + # to either change their hostname or read up other options in + # https://github.com/OctoPrint/OctoPrint/issues/3963 + raise CannotStartServerException( + "OctoPrint cannot start due to a Python bug " + "(https://bugs.python.org/issue26227). Your " + "computer's host name contains non-ASCII characters. " + "Please either change your computer's host name to " + "contain only ASCII characters, or take a look at " + "https://github.com/OctoPrint/OctoPrint/issues/3963 for " + "other options." + ) + else: + raise def serve(): try: @@ -2656,3 +2672,7 @@ class LifecycleManager(object): for event in events: if callback in self._plugin_lifecycle_callbacks[event]: self._plugin_lifecycle_callbacks[event].remove(callback) + + +class CannotStartServerException(Exception): + pass