fix(windows): force UTF-8 in channel subprocesses and MCP server env (#345)
Extracted from #318 (the UTF-8/doctor core, minus the env-wrapper feature): - new agent_reach/utils/process.py: utf8_subprocess_env() + mcporter_utf8_env_args() — Windows GBK consoles otherwise corrupt Chinese output from mcporter/MCP child processes - weibo/douyin/linkedin checks and weibo install/registration now pass the UTF-8 env (and register the MCP server with --env PYTHONUTF8=1) - youtube: extract _has_js_runtime_config() with an OSError guard so an unreadable yt-dlp config can't crash doctor - test_skill_command: open SKILL.md with explicit utf-8 (Windows GBK default broke these tests) Co-authored-by: chidao <2980933590@qq.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+11
-6
@@ -763,6 +763,8 @@ def _install_weibo_deps():
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
from agent_reach.utils.process import mcporter_utf8_env_args, utf8_subprocess_env
|
||||
|
||||
print("Setting up Weibo MCP server...")
|
||||
|
||||
# Check if already installed and working
|
||||
@@ -771,7 +773,8 @@ def _install_weibo_deps():
|
||||
try:
|
||||
r = subprocess.run(
|
||||
[mcporter, "config", "list"], capture_output=True,
|
||||
encoding="utf-8", errors="replace", timeout=5
|
||||
encoding="utf-8", errors="replace", timeout=5,
|
||||
env=utf8_subprocess_env(),
|
||||
)
|
||||
if "weibo" in r.stdout:
|
||||
print(" ✅ Weibo MCP already configured")
|
||||
@@ -784,25 +787,27 @@ def _install_weibo_deps():
|
||||
subprocess.run(
|
||||
[sys.executable, "-m", "pip", "install", "-q",
|
||||
"git+https://github.com/Panniantong/mcp-server-weibo.git"],
|
||||
check=True, timeout=120
|
||||
check=True, timeout=120, env=utf8_subprocess_env()
|
||||
)
|
||||
print(" ✅ mcp-server-weibo installed (Panniantong fork)")
|
||||
except Exception as e:
|
||||
print(f" [!] mcp-server-weibo install failed: {e}")
|
||||
return
|
||||
|
||||
# Register with mcporter
|
||||
# Register with mcporter (force UTF-8 in the server's env — Windows GBK
|
||||
# consoles otherwise corrupt the MCP server's Chinese output)
|
||||
if mcporter:
|
||||
try:
|
||||
subprocess.run(
|
||||
[mcporter, "config", "add", "weibo", "--command", "mcp-server-weibo"],
|
||||
[mcporter, "config", "add", "weibo", "--command", "mcp-server-weibo",
|
||||
*mcporter_utf8_env_args()],
|
||||
check=True, capture_output=True, timeout=10
|
||||
)
|
||||
print(" ✅ Weibo MCP registered with mcporter")
|
||||
except Exception:
|
||||
print(" [!] mcporter config add failed. Run manually: mcporter config add weibo --command 'mcp-server-weibo'")
|
||||
print(" [!] mcporter config add failed. Run manually: mcporter config add weibo --command 'mcp-server-weibo' --env PYTHONUTF8=1 --env PYTHONIOENCODING=utf-8")
|
||||
else:
|
||||
print(" -- mcporter not found, skipping MCP registration. Install mcporter first, then run: mcporter config add weibo --command 'mcp-server-weibo'")
|
||||
print(" -- mcporter not found, skipping MCP registration. Install mcporter first, then run: mcporter config add weibo --command 'mcp-server-weibo' --env PYTHONUTF8=1 --env PYTHONIOENCODING=utf-8")
|
||||
|
||||
|
||||
def _install_wechat_deps():
|
||||
|
||||
Reference in New Issue
Block a user