更新 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:
|
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:
|
||||||
return True
|
# 200 也要检查返回体是否有错误
|
||||||
payload = json.load(response)
|
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):
|
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:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user