Python SDK token refresh loop vs manual refresh

Noticed something odd with our internal Python service. It’s supposed to handle long-running tasks that occasionally hit the /api/v2/analytics/queues/summary endpoint. The script runs fine for a bit, then suddenly throws a 401 Unauthorized.

Here’s the thing. I’m using the genesyscloud Python SDK (v2.28.1). The docs say the SDK handles token refresh automatically if you pass the client credentials correctly. I did that. But it’s not working. The token expires after an hour, and the SDK doesn’t seem to be grabbing a new one before the next request. Instead, it just fails hard.

I’ve been manually calling client.auth.refresh_token() in a try/except block as a workaround, but that feels like fighting the library. Is there a specific config flag I’m missing? Or is the automatic refresh only for certain scopes?

Here’s the init code I’m using:

from genesyscloud import Configuration, ApiClient

config = Configuration()
config.host = "https://api.mypurecloud.com"
config.access_token = initial_token # fetched via client credentials flow
client = ApiClient(configuration=config)

The error is just a standard 401. No helpful message in the body. Just unauthorized. Anyone else seen this with the Python SDK?