We’re running a nightly script to sync user attributes via PATCH /api/v2/users/{id}, and we’re hitting 429 Too Many Requests errors after about 200 calls. The response headers include Retry-After, but the value is inconsistent, sometimes 1s, sometimes 30s. I’ve tried a simple linear delay between requests, but that’s not enough when the rate limit resets. The logs show the 429s start appearing randomly, not just at the end of the batch. It’s messy to parse the headers in Python when the SDK doesn’t expose the raw response easily. Here’s the basic loop we’re using right now, which just crashes on the first 429:
import requests
for user in users:
r = session.patch(f"/api/v2/users/{user['id']}", json=payload)
r.raise_for_status()
What’s the most reliable way to handle this in Python? Should I be checking the Retry-After header and sleeping for that exact duration, or is there a standard exponential backoff library that works well with the Genesys Cloud SDK? We need to process 5000 users without getting throttled for hours. I’ve seen some posts about using the analytics API for bulk updates, but that doesn’t update the user profile attributes we need. Stuck on the implementation details for the retry logic.