Spaces:
Sleeping
Sleeping
kevin
commited on
Commit
·
eaf1a7f
1
Parent(s):
38f0a99
出现429时移除token
Browse files- core/utils.py +11 -0
core/utils.py
CHANGED
|
@@ -274,6 +274,17 @@ async def process_streaming_response(request: ChatRequest, app_secret: str, curr
|
|
| 274 |
)
|
| 275 |
except httpx.HTTPStatusError as e:
|
| 276 |
# 这里需要处理401错误
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
logger.error(f"HTTP error occurred: {e}")
|
| 278 |
raise HTTPException(status_code=e.response.status_code, detail=str(e))
|
| 279 |
except httpx.RequestError as e:
|
|
|
|
| 274 |
)
|
| 275 |
except httpx.HTTPStatusError as e:
|
| 276 |
# 这里需要处理401错误
|
| 277 |
+
|
| 278 |
+
# 处理429错误
|
| 279 |
+
if e.response.status_code == 429:
|
| 280 |
+
token_str = os.getenv('TOKEN', '')
|
| 281 |
+
token_array = token_str.split(',')
|
| 282 |
+
token_array.pop(current_index)
|
| 283 |
+
os.environ["TOKEN"] = ','.join(token_array)
|
| 284 |
+
refresh_token_str = os.getenv('REFRESH_TOKEN', '')
|
| 285 |
+
refresh_token_array = refresh_token_str.split(',')
|
| 286 |
+
refresh_token_array.pop(current_index)
|
| 287 |
+
os.environ["REFRESH_TOKEN"] = ','.join(refresh_token_array)
|
| 288 |
logger.error(f"HTTP error occurred: {e}")
|
| 289 |
raise HTTPException(status_code=e.response.status_code, detail=str(e))
|
| 290 |
except httpx.RequestError as e:
|