1def fetch_with_retry(url, retries=3):
2 for attempt in range(retries):
3 try:
4 return requests.get(url, timeout=5)
5 except Exception as e:
6 if attempt == retries - 1:
7 raise
8 time.sleep(2 ** attempt)
9# Ctrl+C during sleep silently restarts the retry
no lines flagged
#046PracticeMedium15 min · 120 XP
Catching Too Broad an Exception
An API client silently swallows KeyboardInterrupt and SystemExit because the exception handler is too broad.
Flagged linesNo lines flagged yet
What's wrong?
Flag a line or write a note to submit.