更新 tp/scripts/beauty.py

This commit is contained in:
lj091715 2026-05-19 14:05:19 +08:00
parent 5967e4d459
commit d501ec71b2

View File

@ -93,14 +93,23 @@ def send_images(image_urls: list[str]) -> bool:
try: try:
with urllib.request.urlopen(request, timeout=30) as response: with urllib.request.urlopen(request, timeout=30) as response:
body_text = response.read().decode("utf-8", errors="replace")
if 200 <= response.status < 300: if 200 <= response.status < 300:
# 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 return True
payload = json.load(response)
except (urllib.error.URLError, TimeoutError, json.JSONDecodeError, OSError): except (urllib.error.URLError, TimeoutError, json.JSONDecodeError, OSError):
return False return False
code = payload.get("code") return False
return code == 200 or code == 0
def main() -> int: def main() -> int: