Banging my head against the wall here. I’m writing a script to update thousands of users via PUT /api/v2/users/{id}. It works fine for the first 50 calls, then I get hit with a 429 Too Many Requests. My current retry logic is just a simple sleep(1), which is obviously too aggressive.
def update_user(user_id, data):
res = requests.put(f"/api/v2/users/{user_id}", json=data)
if res.status_code == 429:
time.sleep(1)
return update_user(user_id, data)
return res
The response includes a Retry-After header, but parsing that dynamically feels clunky. Is there a standard way to implement exponential backoff that respects the 429 limits without hardcoding delays? Also, should I be batching these requests differently?