fix: add explicit UTF-8 encoding to file operations for Windows compatibility (#1845)

On Windows, Python's default encoding is the system locale (e.g., cp1252,
gbk) rather than UTF-8. This causes UnicodeDecodeError when reading
sdkconfig files, CMakeLists.txt, or JSON configs that contain non-ASCII
characters (e.g., Chinese comments, UTF-8 BOM).

Fix: Add explicit encoding='utf-8' to all text file open() calls in:
- scripts/release.py (Path.open() for config.json, CMakeLists.txt, sdkconfig)
- scripts/build_default_assets.py (io.open() for sdkconfig, open() for headers/configs)
- scripts/versions.py (open() for info.json read/write)

Relates to #1792

Co-authored-by: Nicola Spieser <redbasecap@users.noreply.github.com>
This commit is contained in:
Nicola Urs Bruce Spieser
2026-03-15 11:49:49 +01:00
committed by GitHub
parent d35f03134f
commit bbd5f70c3c
3 changed files with 13 additions and 13 deletions

View File

@ -236,11 +236,11 @@ def main():
target_dir = os.path.join("firmwares", tag)
info["tag"] = tag
info["url"] = os.path.join(os.environ['OSS_BUCKET_URL'], target_dir, "xiaozhi.bin")
open(info_path, "w").write(json.dumps(info, indent=4))
open(info_path, "w", encoding="utf-8").write(json.dumps(info, indent=4))
# upload all file to oss
upload_dir_to_oss(folder, target_dir)
# read info.json
info = json.load(open(info_path))
info = json.load(open(info_path, encoding="utf-8"))
# post info.json to server
post_info_to_server(info)