How do you handle the 429 Too Many Requests error when creating users in bulk via the Python Platform SDK?
We’ve got a CSV file with about 500 new agents that need to be provisioned. I’m writing a script that reads the rows and calls users_api.post_users for each entry. The logic seems sound, but after creating roughly 15 users, the API starts throwing 429 errors. I know there are rate limits, but I’m not sure how to implement a proper backoff strategy within the SDK loop without blocking the entire thread for too long.
Here is the basic loop I’m running:
import csv
from genesyscloud.rest import ApiClient, Configuration
from genesyscloud.users.api import users_api
# ... setup config and client ...
with open('agents.csv', 'r') as f:
reader = csv.DictReader(f)
for row in reader:
user_body = {
'name': row['Name'],
'email': row['Email'],
'division_id': division_id
}
try:
users_api.post_users(body=user_body)
print(f"Created {row['Name']}")
except Exception as e:
print(f"Failed {row['Name']}: {e}")
Is there a built-in method in the SDK to queue these requests or handle the retries automatically? Or should I just use time.sleep and hope for the best? The script keeps crashing hard on the first retry attempt.