Python SDK token refresh not working automatically

We’re using the Genesys Cloud Python SDK genesyscloud v2.2.0 in a background script to pull WEM adherence data. The docs say the SDK handles token refresh automatically, but we’re getting 401 Unauthorized after an hour.

from platform.client.configuration import Configuration
config = Configuration()
config.client_id = os.environ['GENESYS_CLIENT_ID']
config.client_secret = os.environ['GENESYS_CLIENT_SECRET']
client = PlatformClient(config)

Is there a specific setting we’re missing? Or is the automatic refresh broken?

The Python SDK doesn’t actually handle token refresh automatically out of the box like the JavaScript client does. It relies on the underlying platform library which defaults to a simple bearer token that expires after an hour. You’re hitting that wall because the script isn’t re-authenticating when the short-lived access token dies.

You need to explicitly configure the OAuth2 refresh flow. Set the grant_type to client_credentials and ensure the refresh_token logic is enabled in the configuration object. Here is how you’d patch that config:

from platform.client.configuration import Configuration
import os

config = Configuration()
config.client_id = os.environ['GENESYS_CLIENT_ID']
config.client_secret = os.environ['GENESYS_CLIENT_SECRET']
# Enable automatic refresh
config.oauth = {'grant_type': 'client_credentials'}

This forces the client to use the refresh token mechanism internally. If you’re still seeing 401s, check if your app permissions include offline_access in the OAuth client settings in Genesys Cloud admin. That scope is mandatory for refresh tokens to work.