Block 54: Rate Limiting & Robustness
Write production-quality API fetchers that handle errors and limits.
Concepts
- time.sleep() between requests
- Retry logic with a simple loop
- Checking status codes before processing
- Saving raw JSON to file as backup
Code Examples
See exercise below.
Exercise
Write a function fetch_with_retry(url, retries=3) that retries on 5xx errors. Fetch 10 pages of data with a 1-second sleep between each; collect all results.
Homework
Why is it important to save raw API data before processing it? Describe a scenario where this matters. Wednesday