From df0bc19df2e38ec370ca86ecf5da709278d744b1 Mon Sep 17 00:00:00 2001 From: Chaakh Date: Sun, 23 Aug 2026 12:23:06 +0200 Subject: [PATCH] fix: force UTF-8 on stdio so the server starts on a Windows console MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every log line in app.py is emoji-prefixed and a Windows console is cp1252 by default, so _recover_jobs_from_disk() kills the server during startup: print(f"♻️ Recovered {recovered} completed job(s) from disk.") UnicodeEncodeError: 'charmap' codec can't encode characters in 0-1 ERROR: Application startup failed. Exiting. It never binds a port, so the dashboard is simply unreachable on a stock Windows box. PYTHONIOENCODING=utf-8 works around it, but that has to be known before the first run, and the traceback does not suggest it. subtitles._configure_stdio already does exactly this for the transcription path. The server needs it too, and needs it before the first print, so it runs at module scope rather than in the lifespan hook. Verified: uvicorn with no PYTHONIOENCODING, and an import under a stdout forced to cp1252/strict. Both start and log the emoji correctly. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01QiYkHKB7Tp7X6NdnEutda2 --- app.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app.py b/app.py index 9897f1b..03b5803 100644 --- a/app.py +++ b/app.py @@ -64,6 +64,22 @@ MIN_SOURCE_SECONDS = int(os.environ.get("MIN_SOURCE_SECONDS", "45")) QUALITY_PROBE_SCRIPT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "quality_probe.py") DISABLE_YOUTUBE_URL = os.environ.get("DISABLE_YOUTUBE_URL", "false").lower() in ("1", "true", "yes") +# Every log line in this module is emoji-prefixed, and a Windows console is +# cp1252 by default. _recover_jobs_from_disk() prints one during startup, so +# without this the server dies before it ever listens: +# +# UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-1 +# ERROR: Application startup failed. Exiting. +# +# subtitles._configure_stdio solved this for the transcription path; the server +# needs it too, and needs it before the first print. +for _stream in (sys.stdout, sys.stderr): + if hasattr(_stream, "reconfigure"): + try: + _stream.reconfigure(encoding="utf-8", errors="replace") + except Exception: + pass + # ---- Cloud billing (paid / managed-keys) integration -------------------------- # All paid-mode code lives in the optional `cloud/` package and is imported ONLY # when BILLING_ENABLED is set. With the flag off, the app behaves exactly as the