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):