Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -41,6 +41,8 @@ key_status: Dict[str, Dict] = {
|
|
| 41 |
# βββββββββββββββββββββββββββββ
|
| 42 |
def auth(req: Request):
|
| 43 |
auth_header = req.headers.get("Authorization", "").replace("Bearer ", "")
|
|
|
|
|
|
|
| 44 |
# Accept if: (1) it's a valid backend key OR (2) it's master key
|
| 45 |
if auth_header not in API_KEYS and auth_header != MASTER_API_KEY:
|
| 46 |
raise HTTPException(401, "Unauthorized")
|
|
@@ -90,6 +92,7 @@ async def proxy(req: Request, path: str):
|
|
| 90 |
return JSONResponse({"error": "all keys failed"}, status_code=503)
|
| 91 |
|
| 92 |
headers["Authorization"] = f"Bearer {key}"
|
|
|
|
| 93 |
|
| 94 |
try:
|
| 95 |
async with httpx.AsyncClient(timeout=60) as client:
|
|
@@ -138,7 +141,7 @@ async def proxy(req: Request, path: str):
|
|
| 138 |
key_status[key]["fail"] += 1
|
| 139 |
if key_status[key]["fail"] >= 3:
|
| 140 |
mark_dead(key)
|
| 141 |
-
print(f"[ERROR] key={key[:
|
| 142 |
continue
|
| 143 |
|
| 144 |
return JSONResponse(
|
|
|
|
| 41 |
# βββββββββββββββββββββββββββββ
|
| 42 |
def auth(req: Request):
|
| 43 |
auth_header = req.headers.get("Authorization", "").replace("Bearer ", "")
|
| 44 |
+
# DEBUG
|
| 45 |
+
print(f"[AUTH] client_key={auth_header[:15]}..., MASTER={MASTER_API_KEY[:15]}..., API_KEYS_COUNT={len(API_KEYS)}")
|
| 46 |
# Accept if: (1) it's a valid backend key OR (2) it's master key
|
| 47 |
if auth_header not in API_KEYS and auth_header != MASTER_API_KEY:
|
| 48 |
raise HTTPException(401, "Unauthorized")
|
|
|
|
| 92 |
return JSONResponse({"error": "all keys failed"}, status_code=503)
|
| 93 |
|
| 94 |
headers["Authorization"] = f"Bearer {key}"
|
| 95 |
+
print(f"[PROXY] trying key={key[:15]}... -> {BASE_URL}")
|
| 96 |
|
| 97 |
try:
|
| 98 |
async with httpx.AsyncClient(timeout=60) as client:
|
|
|
|
| 141 |
key_status[key]["fail"] += 1
|
| 142 |
if key_status[key]["fail"] >= 3:
|
| 143 |
mark_dead(key)
|
| 144 |
+
print(f"[ERROR] key={key[:15]} -> {type(e).__name__}: {e}")
|
| 145 |
continue
|
| 146 |
|
| 147 |
return JSONResponse(
|