forum configure.py: survive nginx's 429 without a JSON body
Some checks are pending
CI / Integration (mcr.microsoft.com/mssql/server:2025-latest) (push) Blocked by required conditions
CI / Integration (mcr.microsoft.com/mssql/server:2017-latest) (push) Blocked by required conditions
CI / Integration (mcr.microsoft.com/mssql/server:2019-latest) (push) Blocked by required conditions
CI / Integration (mcr.microsoft.com/mssql/server:2022-latest) (push) Blocked by required conditions
CI / Build og unit tests (push) Successful in 1m1s
CI / MSI-installer (push) Successful in 39s
Some checks are pending
CI / Integration (mcr.microsoft.com/mssql/server:2025-latest) (push) Blocked by required conditions
CI / Integration (mcr.microsoft.com/mssql/server:2017-latest) (push) Blocked by required conditions
CI / Integration (mcr.microsoft.com/mssql/server:2019-latest) (push) Blocked by required conditions
CI / Integration (mcr.microsoft.com/mssql/server:2022-latest) (push) Blocked by required conditions
CI / Build og unit tests (push) Successful in 1m1s
CI / MSI-installer (push) Successful in 39s
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) <noreply@anthropic.com>
This commit is contained in:
parent
ce49866d2b
commit
bffb17cc63
1 changed files with 7 additions and 2 deletions
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue