Trying to get the Python SDK to handle token refresh automatically, but it seems stuck on the initial access token. I’ve got a long-running script polling /api/v2/queues/{id}/members every 5 seconds. The docs imply that passing refresh_token to the PureCloudPlatformClientV2 constructor should handle the rest, but after about an hour, I start getting 401s. The SDK doesn’t seem to be catching the error and swapping in the new token. I’ve verified the refresh token is valid by manually swapping it in Postman and getting a 200.
Here’s the init code:
from genesyscloud.platform.client import PureCloudPlatformClientV2
config = {
'clientId': 'my-client-id',
'clientSecret': 'my-secret',
'refreshToken': 'my-refresh-token',
'environment': 'mypurecloud.com'
}
client = PureCloudPlatformClientV2(config)
Then the loop:
while True:
try:
response = client.queue_api.get_queue_member('queue-id', 'member-id')
print(response)
except Exception as e:
print(f"Error: {e}")
time.sleep(5)
The error output is just 401 Client Error: Unauthorized for url: https://api.mypurecloud.com/api/v2/queues/.... No stack trace about refresh failure. I’m running this in a Docker container on Ubuntu, timezone Africa/Lagos. Is there a specific flag or middleware I need to enable for auto-refresh? Or is the Python SDK just broken for this use case? The JS SDK handles this fine, so I’m wondering if I’m missing a config param in Python. I don’t want to manually catch the 401 and call client.oauth_client.refresh() every time. That feels like a hack. Seems like the SDK should abstract this away. Any ideas? I’ve checked the GitHub issues but nothing recent on this. Might be something simple I’m overlooking. The token expiry is standard 1 hour. Refresh token expiry is 30 days. Script runs for 24 hours. Fails at the hour mark. Consistent. Every time. Restarting the container fixes it temporarily. Just want it to keep running. No manual intervention. Feels like the refresh callback isn’t wired up correctly in the Python client. Or maybe the session object isn’t being updated. I’m stumped. Tried logging the oauth client state but it’s opaque. Can’t see what’s happening under the hood. Any pointers? I’ll dig into the source if needed, but would prefer a config fix. Thanks.