QuestionQ516

Using APIs

Complete the Python code below so that it correctly implements API rate-limit handling against the Webex API and retries after waiting less than 1 second by using the server-supplied wait time.

Question Image

Drag & Drop
Retry-After
329
content-type
Retry
str
429
headers dict key (paired with 'application/json')
if response.status_code ==
response.headers.get(...)
print('Too many requests, trying again in ' + ___(retry_time) + ' secs.')
Explanation

HTTP requests to the Webex REST API must include a 'content-type' header set to 'application/json' to specify the request body format. When a client exceeds the API's rate limit, the server responds with HTTP status code 429 (Too Many Requests). That response includes a 'Retry-After' header specifying the number of seconds the client should wait before retrying. Since retry_time is an integer being concatenated into a string with the '+' operator, it must first be converted to a string using str(retry_time); otherwise Python raises a TypeError. The distractors 329 (not a valid HTTP status code) and 'Retry' (not a valid header name or built-in function) are not used.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!