Rest API - Rate Limiting and Throttling
This code snippet is intended to enforce per-IP rate limits but has a bug:
What is the bug and how to fix it?
requests_per_ip = {"1.2.3.4": 8}
ip_limit = 10
ip = "1.2.3.4"
if requests_per_ip[ip] > ip_limit:
print("Limit exceeded")
else:
print("Allowed")What is the bug and how to fix it?
