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: