更新 tp/scripts/beauty.py
This commit is contained in:
parent
5967e4d459
commit
d501ec71b2
@ -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:
|
||||
# 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
|
||||
payload = json.load(response)
|
||||
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:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user