From c91118b17a7e3456ed1e0e3d07ee93d8007327f7 Mon Sep 17 00:00:00 2001 From: kevinchennewbee <200705279@qq.com> Date: Thu, 11 Jun 2026 11:30:25 +0800 Subject: [PATCH] fix(wechat): check the real terminal for QR login, not the log file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit __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. --- frontends/wechatapp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/wechatapp.py b/frontends/wechatapp.py index aff57bf16..807ed4cee 100644 --- a/frontends/wechatapp.py +++ b/frontends/wechatapp.py @@ -415,7 +415,7 @@ def _send(show): print(f'[NEW] Process starting {time.strftime("%m-%d %H:%M")}') bot = WxBotClient() if _do_relogin or not bot.token: - if not sys.stdout.isatty(): + if not (sys.__stdout__ and sys.__stdout__.isatty()): print('[Bot] no token and not interactive, exit.'); sys.exit(1) sys.stdout = sys.stderr = sys.__stdout__ # restore for QR display bot.login_qr()