Python SDK auto-refresh failing on long-running batch job

Running a nightly batch script to update routing queue settings via the Python SDK. The script loops through ~500 queues, fetching and updating configs. It works fine for the first batch, then hits a wall around the 40-minute mark.

The docs say the SDK handles token refresh automatically when using PlatformClient with valid credentials. I’ve got my client_id and client_secret set in the environment, and the initial auth is clean.

from purecloudplatformclientv2 import PlatformClient, RoutingApi

platform_client = PlatformClient()
routing_api = RoutingApi(platform_client)

# Loop starts here
for queue in queues:
 try:
 routing_api.post_routing_queue(queue_id, body=queue_config)
 except Exception as e:
 print(f"Failed on {queue_id}: {e}")
 break

The error isn’t a 401. It’s a generic connection timeout or a 502 from the gateway, but right after that, subsequent calls get 401 Unauthorized. Looks like the refresh token isn’t being swapped in time or the session is stale.

Is there a config flag I’m missing to force a refresh check before each request? Or does the SDK only refresh on the first 401 hit, which is too late if the connection drops mid-stream? We’re on US Central time, so maybe there’s a weird server-side session cleanup happening at 2 AM CT?