From d7071cd4246d4033f57fdd0df7ac86f1ec5c0166 Mon Sep 17 00:00:00 2001 From: woaijiadanoo Date: Sun, 19 Apr 2026 12:22:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20explicit=20UTF-8=20encoding=20on=20all?= =?UTF-8?q?=20read=5Ftext()=20calls=20=E2=80=94=20v0.50.89=20(PR=20#700=20?= =?UTF-8?q?by=20@woaijiadanoo)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes config loading failures on Windows with non-UTF-8 default locales (GBK, Shift_JIS etc). All Path.read_text() calls in api/config.py and api/profiles.py now specify encoding='utf-8'. --- api/config.py | 6 +++--- api/profiles.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/config.py b/api/config.py index 63ff0ba..464e3dd 100644 --- a/api/config.py +++ b/api/config.py @@ -198,7 +198,7 @@ def reload_config() -> None: import yaml as _yaml if config_path.exists(): - loaded = _yaml.safe_load(config_path.read_text()) + loaded = _yaml.safe_load(config_path.read_text(encoding="utf-8")) if isinstance(loaded, dict): _cfg_cache.update(loaded) try: @@ -770,7 +770,7 @@ def get_available_models() -> dict: try: import json as _j - auth_store = _j.loads(auth_store_path.read_text()) + auth_store = _j.loads(auth_store_path.read_text(encoding="utf-8")) active_provider = auth_store.get("active_provider") except Exception: logger.debug("Failed to load auth store from %s", auth_store_path) @@ -818,7 +818,7 @@ def get_available_models() -> dict: env_keys = {} if hermes_env_path.exists(): try: - for line in hermes_env_path.read_text().splitlines(): + for line in hermes_env_path.read_text(encoding="utf-8").splitlines(): line = line.strip() if line and not line.startswith("#") and "=" in line: k, v = line.split("=", 1) diff --git a/api/profiles.py b/api/profiles.py index 5e1e103..bc40414 100644 --- a/api/profiles.py +++ b/api/profiles.py @@ -75,7 +75,7 @@ def _read_active_profile_file() -> str: ap_file = _DEFAULT_HERMES_HOME / 'active_profile' if ap_file.exists(): try: - name = ap_file.read_text().strip() + name = ap_file.read_text(encoding="utf-8").strip() if name: return name except Exception: @@ -142,7 +142,7 @@ def _reload_dotenv(home: Path): return try: loaded_keys: set[str] = set() - for line in env_path.read_text().splitlines(): + for line in env_path.read_text(encoding="utf-8").splitlines(): line = line.strip() if line and not line.startswith('#') and '=' in line: k, v = line.split('=', 1) @@ -344,7 +344,7 @@ def _write_endpoint_to_config(profile_dir: Path, base_url: str = None, api_key: cfg = {} if config_path.exists(): try: - loaded = _yaml.safe_load(config_path.read_text()) + loaded = _yaml.safe_load(config_path.read_text(encoding="utf-8")) if isinstance(loaded, dict): cfg = loaded except Exception: