From bb1f12977a738e9963dacddf6b35a97130da3c85 Mon Sep 17 00:00:00 2001 From: snow-moonlight1 Date: Tue, 21 Jul 2026 14:03:11 +0800 Subject: [PATCH] fix(utils): decode QR image via np.fromfile for non-ASCII paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cv2.imread cannot open files under non-ASCII (e.g. Chinese) paths on Windows, so decode_qrcode_from_path() always returned None when the project lived under a directory like D:\视频全平台同步\, and the terminal QR re-print silently failed. Use np.fromfile + cv2.imdecode instead, which handles arbitrary paths. --- utils/login_qrcode.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/utils/login_qrcode.py b/utils/login_qrcode.py index dda3ed3..13c1cec 100644 --- a/utils/login_qrcode.py +++ b/utils/login_qrcode.py @@ -35,7 +35,13 @@ def remove_qrcode_file(qrcode_path: Path | None) -> bool: def decode_qrcode_from_path(qrcode_path: Path) -> str | None: - image = cv2.imread(str(qrcode_path)) + # Windows 下 cv2.imread 不支持中文路径, 改用 np.fromfile + imdecode + import numpy as np + + try: + image = cv2.imdecode(np.fromfile(str(qrcode_path), dtype=np.uint8), cv2.IMREAD_COLOR) + except Exception: + return None if image is None: return None