Python SDK token refresh hanging in production loop

We’re running a Python script to batch-process interaction data. The script loops through thousands of records, hitting the API every few seconds. Locally it works fine. In production, after about 45 minutes, the requests start timing out. I assumed the access token expired.

I read the docs say the Platform SDK handles token refresh automatically via the refresh_token grant type. So I didn’t write any manual refresh logic. Just initialized the client and let it run.

Here’s the setup:

from nice_cxone.platformsdk import PlatformClient

client = PlatformClient(
 host="api.nice.incontact.com",
 api_key="my-api-key",
 api_secret="my-api-secret"
)

The script crashes with a 401 Unauthorized error. The traceback points to a threading issue in the SDK’s internal cache.

Traceback (most recent call last):
 File "batch.py", line 42, in <module>
 response = client.analytics_api.get_interactions(...)
 File ".../nice_cxone/platformsdk/api/analytics_api.py", line 120, in get_interactions
 return self.call_api('/api/v2/analytics/interactions', 'GET')
nice_cxone.platformsdk.exceptions.ApiException: (401)
Reason: Unauthorized

I tried wrapping the API calls in a try-except block and calling client.auth.refresh_token() manually on failure. That throws a different error: AttributeError: 'PlatformClient' object has no attribute 'refresh_token'. The auth object doesn’t seem to expose that method publicly.

Is there a way to force a refresh? Or is the automatic refresh broken in the current version (v1.2.4)? I’ve seen posts about this in Genesys Cloud, but NICE CXone seems to have a slightly different implementation.

Here’s the request headers I’m seeing in the logs right before the crash:

Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...

The token is definitely expired. The SDK isn’t catching it.

I can’t just restart the script every hour because it loses state. Need a code fix.