From 29d6fac6ccc6f4aeee1f48add68aa42f7b65b15e Mon Sep 17 00:00:00 2001 From: chaos Date: Wed, 8 Jul 2026 15:50:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20401=20=E9=BB=91=E5=90=8D=E5=8D=95?= =?UTF-8?q?=E9=94=81=E6=AD=BB=20-=20=E6=96=B0Token=E4=B9=9F401=E6=97=B6?= =?UTF-8?q?=E6=B8=85=E7=A9=BA=E9=BB=91=E5=90=8D=E5=8D=95=E9=81=BF=E5=85=8D?= =?UTF-8?q?27=E5=88=86=E9=92=9F=E4=B8=8D=E5=8F=AF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ai/huawei_gateway.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/ai/huawei_gateway.py b/ai/huawei_gateway.py index df4cca1..f226313 100755 --- a/ai/huawei_gateway.py +++ b/ai/huawei_gateway.py @@ -879,6 +879,25 @@ def proxy(subpath): timeout=upstream_timeout, stream=True ) + # 如果新 Token 也 401,清空黑名单避免锁死 + if resp.status_code == 401: + resp.close() + logger.warning("新 Token 也 401,清空黑名单避免锁死") + cache._blacklist.clear() + # 再试一次 + new_token2 = find_token_in_memory() + if new_token2: + headers['Authorization'] = f'Bearer {new_token2}' + resp = http_session.request( + method=request.method, + url=target_url, + headers=headers, + data=raw_body, + cookies=request.cookies, + allow_redirects=False, + timeout=upstream_timeout, + stream=True + ) # ============ 429 限流重试 ============ if resp.status_code == 429: