I’m curious as to why the Genesys Cloud Python Platform SDK fails to automatically refresh an expired access token when the client instance is reused from a long-running background thread? I am building a sentiment analysis pipeline that polls the transcript API every 60 seconds. The initial authentication uses PureCloudPlatformClientV2(client_id, client_secret) with OAuth client credentials. According to the documentation, the SDK should handle token lifecycle management internally. However, after approximately 35 minutes, subsequent calls to analytics_api.get_analytics_interactions_export() return a 401 Unauthorized error, indicating the token has expired without being refreshed. I have verified that the refresh_token logic in the underlying requests session is not being invoked. The code initializes the client once at startup and stores it in a module-level variable.
I suspect the issue relates to how the SDK manages the expiration timestamp or threading context. My current implementation looks like this:
from purecloud_platform_client import Configuration, PureCloudPlatformClientV2
import time
config = Configuration(
host='https://api.mypurecloud.com',
client_id='my_client_id',
client_secret='my_client_secret'
)
client = PureCloudPlatformClientV2(config)
while True:
try:
# This call eventually fails with 401
api_response = client.analytics_api.get_analytics_interactions_export(
body={'query': {...}}
)
except Exception as e:
print(f"Error: {e}")
time.sleep(60)
The SDK version is 1.14.0. I have checked the network traffic, and no POST requests to /oauth/token are made after the initial login. Is there a specific configuration flag I am missing to enable automatic refresh, or does the SDK require manual intervention for client credentials flow in long-lived processes?