nerdexam
Cisco

350-901 · Question #94

Refer to the exhibit. Which code snippet completes this code to handle API rate-limit?

The correct answer is C. response.status_code != 429. HTTP status code 429 'Too Many Requests' is the standard response indicating API rate limiting, so the retry loop should check for this code to determine when to back off.

Understanding and Using APIs

Question

Refer to the exhibit. Which code snippet completes this code to handle API rate-limit?

Options

  • Aresponse.status_code != 408
  • Bresponse.status_code != 408
  • Cresponse.status_code != 429
  • Dresponse.status_code == 429

How the community answered

(22 responses)
  • A
    9% (2)
  • C
    86% (19)
  • D
    5% (1)

Why each option

HTTP status code 429 'Too Many Requests' is the standard response indicating API rate limiting, so the retry loop should check for this code to determine when to back off.

Aresponse.status_code != 408

HTTP 408 represents a 'Request Timeout' error where the server did not receive a complete request in time; it is unrelated to rate limiting and checking for it would not correctly handle API throttling.

Bresponse.status_code != 408

HTTP 408 represents a 'Request Timeout' and is not the correct status code for rate-limit detection; this choice is identical to choice A and equally incorrect.

Cresponse.status_code != 429Correct

HTTP status code 429 is defined in RFC 6585 as the standard indicator that the client has sent too many requests in a given time window and the server is rate-limiting the response. Using 'response.status_code != 429' as a loop or condition check allows the code to continue execution when the request is successful and to break or handle the retry logic specifically when rate limiting is encountered. Status 408 is a request timeout, which is a different error unrelated to rate limiting.

Dresponse.status_code == 429

While 429 is the correct rate-limit status code, using '== 429' instead of '!= 429' inverts the intended logic for the conditional structure shown, causing the code to behave incorrectly for the retry-exit pattern depicted.

Concept tested: HTTP 429 rate-limit error handling in API clients

Source: https://datatracker.ietf.org/doc/html/rfc6585#section-4

Topics

#API Rate Limiting#HTTP Status Codes#Python requests#Error Handling

Community Discussion

No community discussion yet for this question.

Full 350-901 Practice