Complete the code to retry the API call once if it fails.
response = requests.get(url) if response.status_code != 200: response = requests.[1](url)
The retry should use the same HTTP method get to fetch the resource again.
Complete the code to catch exceptions during the API call and retry once.
try: response = requests.get(url) except [1]: response = requests.get(url)
Use requests.exceptions.RequestException to catch all request-related errors.
Fix the error in the retry logic to limit retries to 3 attempts.
max_retries = 3 attempt = 0 while attempt < max_retries: try: response = requests.get(url) if response.status_code == 200: break except requests.exceptions.RequestException: pass [1] += 1
The variable attempt must be incremented to count retries and avoid infinite loops.
Fill both blanks to create a dictionary comprehension that retries only for status codes 500 or 502.
retry_status = {code: True for code in [[1], [2]]}Status codes 500 and 502 indicate server errors where retrying is appropriate.
Fill all three blanks to build a retry loop that waits 2 seconds between attempts and stops after 5 tries.
import time max_attempts = [1] attempt = 0 while attempt < max_attempts: try: response = requests.get(url) if response.status_code == 200: break except requests.exceptions.RequestException: pass time.sleep([2]) attempt [3] 1
The loop retries 5 times, waits 2 seconds between tries, and increments attempt by 1 each time.