The 429 status code means the client has sent too many requests in a given amount of time, triggering rate limiting.
429 status code tells the client to slow down because it has sent too many requests in a short time.
If the server's rate limit is too low or misconfigured, it may block even low-frequency requests with 429 errors.
The Retry-After header tells the client how long to wait before retrying after a 429 response.
from flask import Flask, request, jsonify import time app = Flask(__name__) request_times = {} @app.route('/api') def api(): ip = request.remote_addr now = time.time() times = request_times.get(ip, []) # Remove timestamps older than 10 seconds times = [t for t in times if now - t < 10] if len(times) >= 3: return jsonify({'error': 'Too many requests'}), 429 times.append(now) request_times[ip] = times return jsonify({'message': 'Success'}) # Simulate 4 requests from same IP quickly ip = '192.168.1.1' for i in range(4): request_times[ip] = [time.time() - 1, time.time() - 2, time.time() - 3] now = time.time() times = request_times.get(ip, []) times = [t for t in times if now - t < 10] if len(times) >= 3: print(429) else: times.append(now) request_times[ip] = times print(200)
The code allows 3 requests within 10 seconds. The 4th request triggers 429.
