Fix: EL-Retry bei 429 (Free-Tier-Concurrency) + index.html no-cache (immer frisches Bundle)

5 parallele EL-Calls -> 1x 502 (Concurrency-Limit). elevenlabs_tts retryt jetzt 429/5xx mit Backoff.
index.html wird nicht mehr gecacht -> nach Deploy kein altes Bundle mehr.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hitonabi
2026-06-28 02:02:50 +02:00
parent 6d7a17e765
commit dd4c4c8c0f
2 changed files with 22 additions and 9 deletions
+20 -8
View File
@@ -233,14 +233,26 @@ def elevenlabs_tts(text: str, voice: str) -> bytes:
data=body,
headers={"xi-api-key": key, "Content-Type": "application/json", "Accept": "audio/mpeg"},
)
try:
with urllib.request.urlopen(req, timeout=60) as r:
return r.read()
except urllib.error.HTTPError as e:
detail = e.read()[:200].decode("utf-8", "replace")
raise HTTPException(502, f"ElevenLabs-Fehler {e.code}: {detail}")
except urllib.error.URLError as e:
raise HTTPException(502, f"ElevenLabs nicht erreichbar: {e}")
import time
# Free-Tier hat ein Concurrency-Limit → parallele Sätze geben 429. Retry mit Backoff fängt das ab.
last = ""
for attempt in range(4):
try:
with urllib.request.urlopen(req, timeout=60) as r:
return r.read()
except urllib.error.HTTPError as e:
last = f"{e.code}: {e.read()[:200].decode('utf-8', 'replace')}"
if e.code in (429, 500, 502, 503, 529) and attempt < 3:
time.sleep(0.5 * (attempt + 1))
continue
raise HTTPException(502, f"ElevenLabs-Fehler {last}")
except urllib.error.URLError as e:
last = str(e)
if attempt < 3:
time.sleep(0.5 * (attempt + 1))
continue
raise HTTPException(502, f"ElevenLabs nicht erreichbar: {last}")
raise HTTPException(502, f"ElevenLabs-Fehler (nach Retries): {last}")
def elevenlabs_list() -> list[dict]: