From f864c97f2a8554d644905352f13120376a0d564b Mon Sep 17 00:00:00 2001 From: Master Date: Mon, 22 Jun 2026 11:22:49 +0200 Subject: [PATCH] fix: forcage UTF-8 + ask() resistant aux erreurs d'encodage (anti-crash SSH) --- facilitator_v9.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/facilitator_v9.py b/facilitator_v9.py index 3153d28..1f98cf5 100644 --- a/facilitator_v9.py +++ b/facilitator_v9.py @@ -44,6 +44,15 @@ import requests import yaml from dotenv import load_dotenv +# ── Forçage UTF-8 des entrées/sorties ──────────────────────────────────────── +# Évite les UnicodeDecodeError sur les accents en session SSH dont la locale +# n'est pas en UTF-8. Indépendant de LANG/LC_ALL du système. +for _stream in (sys.stdin, sys.stdout, sys.stderr): + try: + _stream.reconfigure(encoding="utf-8", errors="replace") + except (AttributeError, ValueError): + pass # flux non reconfigurable (rare) — on continue + load_dotenv() # ───────────────────────────────────────────────────────────────────────────── @@ -115,6 +124,11 @@ def ask(prompt: str) -> str: except (EOFError, KeyboardInterrupt): print("\n Session interrompue.") sys.exit(0) + except UnicodeDecodeError: + # Faute d'encodage (locale SSH non-UTF-8) : on ne tue pas la session. + warn("Caractère mal encodé ignoré. Relance ta saisie " + "(ou préfixe la commande par PYTHONUTF8=1 au prochain lancement).") + return "" def ask_multiline(end_marker: str = ".") -> str: @@ -128,6 +142,9 @@ def ask_multiline(end_marker: str = ".") -> str: line = input() except (EOFError, KeyboardInterrupt): break + except UnicodeDecodeError: + warn("Ligne mal encodée ignorée.") + continue if line.strip() == end_marker: break lines.append(line)