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

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