Ensure UTF-8 encoding for config.json read/write in config.py#29
Open
mrmeixiang wants to merge 3 commits intoylytdeng:mainfrom
Open
Ensure UTF-8 encoding for config.json read/write in config.py#29mrmeixiang wants to merge 3 commits intoylytdeng:mainfrom
mrmeixiang wants to merge 3 commits intoylytdeng:mainfrom
Conversation
ylytdeng
requested changes
Mar 14, 2026
Owner
ylytdeng
left a comment
There was a problem hiding this comment.
评审意见
问题定位准确,修复方向正确,但覆盖范围严重不足。
严重问题
补丁不完整 — 只修了 config.py 3 处,但项目中还有 9+ 处同类问题未修复:
| 文件 | 问题 |
|---|---|
mcp_server.py L31 |
open(CONFIG_FILE) 未指定 encoding |
mcp_server.py L54 |
open(KEYS_FILE) 未指定 encoding |
mcp_server.py L145/174 |
缓存 JSON 读写未指定 encoding |
main.py L31/62 |
open(keys_file) 未指定 encoding |
decrypt_db.py L119 |
open(KEYS_FILE) 未指定 encoding |
monitor.py L152 |
open(KEYS_FILE) 未指定 encoding |
monitor_web.py L1886 |
open(KEYS_FILE) 未指定 encoding |
这些文件在 Windows GBK 环境下同样会报 UnicodeDecodeError。
建议
- 扩大修改范围,一次性修完所有
open()调用 - 或者提取通用工具函数
load_json_file(path)/save_json_file(path, data),集中处理编码 - 如果想分步提交,可以先合并此 PR,但必须立即跟进覆盖其余文件的 PR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
将 config.py 中 config.json 的读写统一显式指定为 UTF-8 编码,修复 Windows 中文环境下因默认编码差异导致的配置解析异常。