From 0ffbf20f6b506b8feeb9a27b04067399390d602a Mon Sep 17 00:00:00 2001 From: chaos Date: Wed, 8 Jul 2026 16:51:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20compact=E5=86=85=E9=83=A8401=E5=88=B7?= =?UTF-8?q?=E6=96=B0Token=E9=87=8D=E8=AF=95+=E6=B8=85=E7=A9=BA=E9=BB=91?= =?UTF-8?q?=E5=90=8D=E5=8D=95=E9=98=B2=E9=94=81=E6=AD=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ai/huawei_gateway.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ai/huawei_gateway.py b/ai/huawei_gateway.py index b343e8f..adb5bfa 100755 --- a/ai/huawei_gateway.py +++ b/ai/huawei_gateway.py @@ -660,6 +660,21 @@ def compact_endpoint(): timeout=UPSTREAM_TIMEOUT_MAX, stream=False ) + # 401 时刷新 Token 重试 + if resp.status_code == 401: + logger.warning(f"compact: 第{i+1}批收到 401,刷新Token重试...") + cache.blacklist_current() + new_token = find_token_in_memory() + if new_token: + headers['Authorization'] = f'Bearer {new_token}' + resp = http_session.request( + method='POST', url=target_url, headers=headers, + data=batch_body, allow_redirects=False, + timeout=UPSTREAM_TIMEOUT_MAX, stream=False + ) + if resp.status_code == 401: + cache._blacklist.clear() + # compact 内部 429/504 重试 for _retry in range(3): if resp.status_code not in (429, 504):