Python requests: Getting 401 on Genesys OAuth Client Credentials flow

Hey folks,

I’m trying to script a simple token fetcher using Python’s requests library so I can automate some queue config updates. I’ve got the client ID and secret from the Dev Center, and I’m hitting the https://api.mypurecloud.com/oauth/token endpoint. My code looks pretty standard, just passing the grant type and credentials in the body, but I keep hitting a 401 Unauthorized. I’ve double-checked the credentials, and they work fine in Postman, so I’m not sure what’s different here.

Here’s the snippet I’m running. It seems like the headers might be off, or maybe I’m missing a scope? The response body is just {'error': 'invalid_client', 'error_description': 'Bad client credentials'}. I’ve tried adding the Content-Type header explicitly, but no luck. Any idea why the library call is failing while the manual request works?