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")