350-901 · Question #68
350-901 Question #68: Real Exam Question with Answer & Explanation
This question assesses the test-taker's ability to complete a Python script that implements a robust API retry mechanism using exponential backoff and a maximum retry limit, specifically handling HTTP 429 status codes.
Question
The script uses the Cisco Intersight REST API. Drag and drop the code snippets from the left onto the item numbers on the right to match the missing sections in the Python script to update the firmware on specific Cisco Intersight USC rack server.DMZ_R3-ADJM. Not all code snippets are used.
Explanation
This question assesses the test-taker's ability to complete a Python script that implements a robust API retry mechanism using exponential backoff and a maximum retry limit, specifically handling HTTP 429 status codes.
Approach. The correct interaction is to drag the appropriate code snippets to their corresponding numbered items based on standard retry logic and Python syntax:
- Drag '429' to
<item 1>: Inside theexceptblock, theif (response.status_code != <item 1>)condition checks if the error status code is not a specifically retriable one (like 429 'Too Many Requests'). If it's a different, likely non-transient error (e.g., 400, 401, 404, 500), or if the retry limit is hit, the script should return. By checkingresponse.status_code != 429, we ensure that if a 429 error occurs and the retry limit isn't met, the script proceeds to sleep and retry, which is the intended behavior for transient 'Too Many Requests' errors. - Drag 'RETRIES' to
<item 2>: The conditioni >= <item 2>determines if the maximum number of retries has been exhausted.RETRIESis initialized to 6, serving as the upper limit for the retry counteri. - Drag 'backoff' to
<item 3>: Thetime.sleep(<item 3>)function pauses the script for a duration specified by thebackoffvariable. This implements the wait time before the next retry attempt. - Drag 'backoff' to
<item 4>: The line<item 4> *= 2is responsible for doubling thebackoffduration, implementing the exponential backoff strategy for subsequent retries. - Drag 'i' to
<item 5>: The line<item 5> += 1increments the retry counteriafter each failed attempt, moving towards theRETRIESlimit.
Common mistakes.
- common_mistake. Common mistakes include incorrectly assigning the variables:
- Using 'i' or 'RETRIES' for
<item 3>or<item 4>: 'i' is the retry count, not a sleep duration, and 'RETRIES' is a constant for the maximum attempts, not a dynamic sleep variable. This would break the exponential backoff or the sleep mechanism. - Using '429' for
<item 2>: '429' is an HTTP status code, not a retry limit. Comparing the retry count 'i' against '429' makes no logical sense in this context. - Swapping 'i' and 'backoff' for
<item 4>and<item 5>: This would incorrectly increment the backoff variable and exponentially multiply the retry counter, leading to a dysfunctional retry mechanism.
Concept tested. API error handling, retry mechanisms, exponential backoff, HTTP status codes (specifically 429 Too Many Requests, which indicates rate limiting and often warrants retries), Python's try-except blocks, while True loops, and basic variable manipulation.
Topics
Community Discussion
No community discussion yet for this question.