ETExamTower
Q11Using APIs

Refer to the exhibit. The self-service Webex bot fails when many users try to interact with it simultaneously. Drag the code snippets from the left to the matching item numbers to complete the code for this high-load situation. <DragDrop items={["429","backoff","backoff","RETRIES","i"]} slots={[{"answer":"429","id":"item1"},{"answer":"RETRIES","id":"item2"},{"answer":"backoff","id":"item3"},{"answer":"backoff","id":"item4"},{"answer":"i","id":"item5"}]} template={"RETRIES = 6\ni = 0\nbackoff = 1\n\nwhile True:\n try:\n response = requests.request(*args, **kwargs)\n response.raise_for_status()\n return response\n except Exception as e:\n if (response.status_code != {{item1}}) or i == {{item2}}:\n return response\n\n time.sleep({{item3}})\n {{item4}} *= 2\n {{item5}} += 1"} reuse={true} explanation={"HTTP 429 indicates rate limiting, so it is the status that should be retried. The retry counter must be compared with RETRIES to stop after the configured maximum. Exponential backoff sleeps for the current backoff duration, doubles that duration before the next retry, and increments the attempt counter."} />

Question exhibit
← → navigate · a answer
Discussion · 8
60
correct answer should be as follows: Item 1 = 429 Item 2 = RETRIES Item 3 = backoff Item 4 = backoff Item 5 = i
2
Agree with wunderup's answer
2
Agree with wunderup!
2
1. 429 2. RETRIES 3. backoff 4. backoff 5. i
2
1. 429 2. RETRIES (6) 3. backoff (=1) 4. backoff (=2) 5. i (=1)
1
Nothing makes sense to me in this code, can someone explain please ? response.status_code shouldn't be == 429 ? what is the point of i = 0 ? Thanks !!
1
Answer: 1. 429 2. RETRIES 3. backoff 4. backoff 5. i Rationale: 1. if it's not a 429, we know we're not rate-limited [the question prompt is about failing when too many users attempt it at the same time]. so if it's not a 429, we're OK [not always true, but for the sake of this code we are] 2. if we reach the RETRIES number, we should return the response 3. backoff goes here, since we'd sleep for the backoff time period 4. backoff goes here, so we get an exponential backoff [doubles each interval] 5. i goes here, and i is incremented by 1 each time through you asked about i = 0 is is being used as a counter. we increment i each time through the code, until it reaches 6, which is our RETRIES value. thus, you can say if i = RETRIES, then you want to exit the loop. if you're wondering where i would be incremented, you can see the i += 1, at the bottom of the code. Hope this explanation makes sense. Sample code to show why i = 0 in the code. i = 0 while True: print(i) i += 1 if i == 10: # Replace 10 with your desired upper limit break
1
I think this exam expects you to already have Python basics down pat. If that is not the case, then you can probably find plenty of free Python courses out there that cover the basics. (freecodecamp or similar sites) Questions like this would be much easier after that.