Add retry with exponential backoff to HTTP calls without writing the loop yourself.

IntermediateHands-onPython for DevOps
Answer
import requests
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry

retry = Retry(
    total=5,
    backoff_factor=1,                  # sleeps grow exponentially between attempts
    status_forcelist=[429, 500, 502, 503, 504],
    allowed_methods=["GET", "PUT", "DELETE"],
    respect_retry_after_header=True,
)
s = requests.Session()
s.mount("https://", HTTPAdapter(max_retries=retry))
resp = s.get("https://api.example.com/items", timeout=5)

Key trick → POST is left out of allowed_methods on purpose, because retrying a non-idempotent call can create duplicates. Retry-After is honoured for 429s.

All Real-World Interview questions Roadmap: Interview readiness

More on Python for DevOps