Catalog108 / challenges / api/rest/flaky

Flaky API (random 30% failures)

intermediate Matching curriculum →

What this challenge teaches

Teaches: Real APIs fail intermittently. Implement retry with exponential backoff.

Expected output: Hit ?json=1 with retries; succeed within ~3 attempts on average.

Submit your scraper's JSON output to /challenges/api/rest/flaky/grade (grader endpoint is part of a later phase; URL is reserved now).

# Retry with exponential backoff
import requests, time, random
def get_flaky():
    delay = 1.0
    for attempt in range(6):
        r = requests.get("https://practice.scrapingcentral.com/challenges/api/rest/flaky?json=1")
        if r.status_code == 200: return r.json()
        time.sleep(delay + random.random() * 0.5)
        delay *= 2
    raise RuntimeError("gave up after retries")