Bird
0
0

Consider this API client code snippet:

medium📝 Predict Output Q5 of 15
Rest API - HTTP Status Codes

Consider this API client code snippet:

response = api_call()
if response.status_code == 429:
    retry_after = int(response.headers.get('Retry-After', '60'))
    print(f"Wait {retry_after} seconds before retrying")

What will this code print if the server responds with status 429 and no Retry-After header?

AWait None seconds before retrying
BWait 60 seconds before retrying
CWait 0 seconds before retrying
DNo output printed
Step-by-Step Solution
Solution:
  1. Step 1: Check how Retry-After header is accessed

    Code uses get with default '60' if header missing.
  2. Step 2: Convert default string '60' to int

    int('60') is 60, so retry_after is 60.
  3. Final Answer:

    Wait 60 seconds before retrying -> Option B
  4. Quick Check:

    Missing Retry-After defaults to 60 seconds [OK]
Quick Trick: Default Retry-After value used if header missing [OK]
Common Mistakes:
MISTAKES
  • Assuming missing header means zero wait
  • Not converting string to int
  • Expecting no output if header missing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes