Running into a weird issue with the Nice CXone Python SDK nicecxone version 2.1.0. I’ve got a background job that pulls historical analytics data every 5 minutes. The script initializes the client with client ID and secret, which works fine initially. But after about an hour, requests start failing with 401 Unauthorized.
I assumed the SDK handles token refresh automatically under the hood, similar to how the JavaScript client behaves. It seems like it’s not refreshing the access token before it expires. The docs mention an oauth_token method but nothing explicit about auto-refresh logic for long-running processes.
Here’s the setup:
from nicecxone import PlatformClient
client = PlatformClient(
host='api.mynicecxone.com',
client_id='my_client_id',
client_secret='my_client_secret'
)
# Initial call works
response = client.analytics.get_analytics_details(...)
After 50-60 minutes, any subsequent call to client.analytics... throws a 401. I tried manually calling client.oauth_token.refresh() in a loop, but that feels wrong and breaks the abstraction.
Is there a specific configuration flag to enable auto-refresh? Or do I need to wrap the client in a custom class that catches the 401 and re-authenticates? The standard examples don’t cover this long-running use case. I’m using Python 3.9.
Tried checking the network traffic with Wireshark, and I see the SDK making a POST to /api/v2/oauth/token right before the 401, but the response body indicates the refresh token is invalid or expired. Maybe the refresh token itself has a shorter lifespan than the access token in this setup?
Any pointers on how to handle this without rewriting the auth logic?