runtime
389 / 500
question 389 Async Python · hard

Follow next-page links, retrying busy pages

An earthquake feed is split into pages; each page's JSON has "features" and a "next" URL (null on the last page). Pages must be read in order, because each one tells you the next. Write all_features(transport, first_url, retries): follow the links, retrying a page that answers 503 up to retries extra times (waiting 0.5 s between tries), and return every feature's id in order. A page that still fails, or answers anything else that isn't 200, raises HTTPStatusError.

Simulated: this runs against results recorded on real Python.

Coroutineasync def all_features(transport, first_url, retries)
Pages{"features": [...], "next": url or None}
Returnsthe id of every feature, page by page
Errors503 → wait 0.5 s and retry (at most retries retries per page); other non-200 statuses, or a 503 after the last retry → raise_for_status()

Loading your progress…

Follow next-page links, retrying busy pages — Python practice · Runtime