Trying to bulk-create users from a CSV using the Genesys Cloud Python SDK. The script works fine for small batches, but once I push it past ~50 users, the API starts throwing 429s. I’ve implemented a basic exponential backoff, but it feels like the SDK’s internal retry logic is fighting my custom sleep or something. The script hangs indefinitely after a few failures.
Here’s the gist of the loop:
from genesyscloud import PlatformClientConfiguration, UsersApi
import csv
import time
config = PlatformClientConfiguration(client_id, client_secret)
users_api = UsersApi(config)
def create_user(user_data):
try:
resp = users_api.post_users(body=user_data)
return resp
except Exception as e:
if e.status == 429:
wait_time = 2 ** e.retry_after or 5
time.sleep(wait_time)
return create_user(user_data)
raise
with open('users.csv') as f:
reader = csv.DictReader(f)
for row in reader:
create_user(row)
Tried these things:
- Checking the
Retry-Afterheader in the 429 response. It’s usually 5-10 seconds. - Increasing the initial sleep to 10s. Doesn’t help much.
- Looking at the SDK source. Seems like
PlatformClientConfigurationhandles retries, but I’m not sure if I can disable it to handle it manually.
The Retry-After value in the exception object is sometimes None, which breaks my logic. Is there a better way to handle this in the SDK? Or am I missing a config option to throttle requests properly?