fix: explicit UTF-8 encoding on all read_text() calls — v0.50.89 (PR #700 by @woaijiadanoo)

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'.
This commit is contained in:
woaijiadanoo
2026-04-19 12:22:28 +08:00
committed by GitHub
parent e0ad593801
commit d7071cd424
2 changed files with 6 additions and 6 deletions

View File

@@ -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)

View File

@@ -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: