From b37691c95631cf5c7d8bfb1e0b7d0293cdae9475 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Wed, 17 Jan 2024 00:18:03 +0800 Subject: [PATCH] fix: status 522 cannot reload --- func/client.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/func/client.py b/func/client.py index 064a5be..dd3102e 100644 --- a/func/client.py +++ b/func/client.py @@ -1,6 +1,6 @@ import asyncio -from httpx import AsyncClient, TimeoutException +from httpx import AsyncClient, TimeoutException, HTTPStatusError headers = { "authority": "api-static.mihoyo.com", @@ -22,9 +22,15 @@ client = AsyncClient(headers=headers, timeout=120.0) def retry(func): async def wrapper(*args, **kwargs): - for i in range(3): + for i in range(5): try: return await func(*args, **kwargs) + except HTTPStatusError as exc: + if exc.response.status_code == 522: + print(f"重试 {func.__name__} {i + 1} 次") + await asyncio.sleep(1) + else: + raise exc except TimeoutException: print(f"重试 {func.__name__} {i + 1} 次") await asyncio.sleep(1)