From bffb17cc63035ea3c949da06151c0d5675bd5424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Eggert=20Lundsteen=20Olsen?= Date: Wed, 30 Sep 2026 10:44:35 +0200 Subject: [PATCH] forum configure.py: survive nginx's 429 without a JSON body The nginx rate limiter in front of Discourse (web.ratelimited) answers 429 with an HTML page, so reading wait_seconds as JSON crashed the script halfway through creating categories. Fall back to Retry-After or 10 s. Co-Authored-By: Claude Opus 5.5 (1M context) --- deploy/forum/configure.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/deploy/forum/configure.py b/deploy/forum/configure.py index f433afd..1bfe6da 100755 --- a/deploy/forum/configure.py +++ b/deploy/forum/configure.py @@ -89,8 +89,13 @@ def call(method, path, data=None): return json.loads(text) if text else {} except urllib.error.HTTPError as error: body = error.read().decode() - if error.code == 429: # Discourse rate limit: wait as told, then try again - time.sleep(json.loads(body).get("extras", {}).get("wait_seconds", 10) + 1) + if error.code == 429: # rate limit: wait as told, then try again + # Rails answers with JSON; the nginx limiter in front (web.ratelimited) with an HTML page. + try: + wait = json.loads(body).get("extras", {}).get("wait_seconds", 10) + except ValueError: + wait = int(error.headers.get("Retry-After") or 10) + time.sleep(wait + 1) continue sys.exit(f"{method} {path}: {error.code} {body[:300]}") sys.exit(f"{method} {path}: stadig begrænset efter flere forsøg")