Skip to content

fix(wechat): check the real terminal for QR login, not the log file#597

Open
kevinchennewbee wants to merge 1 commit into
lsdefine:mainfrom
kevinchennewbee:fix/wechat-qr-isatty
Open

fix(wechat): check the real terminal for QR login, not the log file#597
kevinchennewbee wants to merge 1 commit into
lsdefine:mainfrom
kevinchennewbee:fix/wechat-qr-isatty

Conversation

@kevinchennewbee

Copy link
Copy Markdown
Contributor

现象:终端里跑 python frontends/wechatapp.py 永远打出 no token and not interactive 退出,首次扫码绑定走不通。

根因:__main__ 先把 sys.stdout 重定向到日志文件,之后才 isatty() —— 检查对象是日志文件,永远非 tty。

修法:改查 sys.__stdout__(真实终端),加 None 防护(pythonw 场景)。+1/−1。

实测:无头 Ubuntu 服务器,此前必须单写脚本调 WxBotClient().login_qr() 才能绑定,修后主入口直接可扫码。

__main__ redirects sys.stdout to the log file before the isatty()
check, so the check always sees a file (never a tty) and the QR
login path is unreachable — running 'python frontends/wechatapp.py'
in a terminal exits with 'no token and not interactive'. Check
sys.__stdout__ (the original terminal) instead; None-guarded for
pythonw. Verified on a headless Ubuntu box where first-time QR
binding previously required a separate login script.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant