Fix: LibreCrawl crashes on Windows when its output is redirected

Windows encodes redirected stdout in cp1252, so the first log line with an
emoji (the SECRET_KEY warning) raised UnicodeEncodeError and main.py exited
before the server started. Hit by the Windows CI job; also affects anyone
logging to a file or running it as a service. A console window is fine,
which is why it went unnoticed. Reconfigure stdout/stderr to UTF-8.
This commit is contained in:
phialsbasement committed 2026-11-10 08:22:42 +11:00
1 parent b4d2e7e3f5
commit 5198986373
1 file changed
+5
+5
View File
@@ -10,10 +10,15 @@ import secrets
import string
import os
import re
import sys
import base64
from io import StringIO, BytesIO
from datetime import datetime, timedelta
# UTF-8 output everywhere: Windows writes redirected output in cp1252, which can't encode the log's emoji
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
sys.stderr.reconfigure(encoding='utf-8', errors='replace')
# Load .env before importing src modules: several of them (email_service's
# SMTP settings, for one) read environment variables at import time.
from dotenv import load_dotenv