0
0
Rest APIprogramming~10 mins

429 Too Many Requests in Rest API - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the HTTP status code for too many requests.

Rest API
response.status_code = [1]
Drag options to blanks, or click blank then click option'
A200
B404
C429
D500
Attempts:
3 left
💡 Hint
Common Mistakes
Using 200 instead of 429
Using 404 which means Not Found
Using 500 which means Server Error
2fill in blank
medium

Complete the code to add a Retry-After header with 60 seconds.

Rest API
response.headers['[1]'] = '60'
Drag options to blanks, or click blank then click option'
ARetry-After
BContent-Type
CAuthorization
DUser-Agent
Attempts:
3 left
💡 Hint
Common Mistakes
Using Content-Type instead of Retry-After
Using Authorization header incorrectly
Forgetting to set the Retry-After header
3fill in blank
hard

Fix the error in the code to correctly check if the status code is 429.

Rest API
if response.status_code [1] 429:
    print('Rate limit exceeded')
Drag options to blanks, or click blank then click option'
A==
B<
C!=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using != instead of ==
Using < or > which check less or greater, not equality
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps IPs to their request counts only if count is greater than 100.

Rest API
ip_counts = {ip: [1] for ip, count in requests.items() if count [2] 100}
Drag options to blanks, or click blank then click option'
Acount
B<
C>
Dip
Attempts:
3 left
💡 Hint
Common Mistakes
Using ip instead of count as value
Using < instead of > in the condition
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps user IDs to their names only if their request count is less than 50.

Rest API
user_names = { [1]: [2] for [3], data in users.items() if data['requests'] < 50 }
Drag options to blanks, or click blank then click option'
Auser_id
Bdata['name']
Dusers
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'users' instead of 'user_id' as loop variable
Using data['requests'] >= 50 instead of < 50
Mixing up keys and values in the comprehension