We’re migrating a legacy Python script that manually calls the OAuth token endpoint to use the official Genesys Cloud Platform SDK. The script processes about 20k contacts in a single run, updating attributes via the /api/v2/contacts endpoint. I initialized the client with genesyscloud.init_from_config(config). I assumed the SDK would handle the token refresh automatically when the access token expires. It’s not. About halfway through the batch, the script starts throwing 401 Unauthorized errors. The error response is standard: {"error": "invalid_token", "error_description": "Access token expired"}. I checked the SDK version and it’s the latest stable release for Python. The documentation says the client should auto-refresh, but clearly something is off in our implementation or the environment config.
I’ve tried a few things. First, I added a retry decorator around the API calls, but that just delays the failure. Second, I manually inserted a client.oauth_client.refresh_token() call every 500 iterations, which works, but it defeats the purpose of using the SDK’s built-in refresh logic. Third, I verified the client secret and app credentials are correct since the initial token fetch works fine. The issue seems to be that the SDK isn’t triggering the refresh before the next request is made. Is there a specific setting in the config object I’m missing? Or do I need to wrap the SDK calls in a specific thread-safe manner for the refresh hook to trigger? The script runs sequentially, so concurrency isn’t the issue here. Just need the tokens to stay valid without manual intervention.