From d501ec71b2ceafac11395fa157e83c0a517a8cd9 Mon Sep 17 00:00:00 2001 From: lj091715 <1091062319@qq.com> Date: Tue, 19 May 2026 14:05:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20tp/scripts/beauty.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tp/scripts/beauty.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tp/scripts/beauty.py b/tp/scripts/beauty.py index 7da5520..e71ead2 100644 --- a/tp/scripts/beauty.py +++ b/tp/scripts/beauty.py @@ -93,14 +93,23 @@ def send_images(image_urls: list[str]) -> bool: try: with urllib.request.urlopen(request, timeout=30) as response: + body_text = response.read().decode("utf-8", errors="replace") if 200 <= response.status < 300: - return True - payload = json.load(response) + # 200 也要检查返回体是否有错误 + try: + result = json.loads(body_text) + code = result.get("code") + if code == 200 or code == 0: + return True + # 返回了200但code不对,打印错误 + sys.stdout.write(f"[debug] 发图接口返回异常: {body_text[:200]}\n") + return False + except (json.JSONDecodeError, AttributeError): + return True except (urllib.error.URLError, TimeoutError, json.JSONDecodeError, OSError): return False - code = payload.get("code") - return code == 200 or code == 0 + return False def main() -> int: