Python requests OAuth2 Client Credentials returning 401 despite correct secrets

Hey folks,

Stuck on a basic auth flow for our Genesys Cloud integration. I’m writing a quick Python script to grab an access token using the client credentials grant, but I keep hitting a 401 Unauthorized. The secrets are definitely correct since they work in Postman.

Here’s the snippet:

import requests

url = "https://api.mypurecloud.com/oauth/token"
headers = {
 "Content-Type": "application/x-www-form-urlencoded"
}
payload = {
 "grant_type": "client_credentials",
 "client_id": "my-client-id",
 "client_secret": "my-client-secret"
}

response = requests.post(url, headers=headers, data=payload)
print(response.status_code)
print(response.text)

The response body just says {"error":"invalid_client"}.

I’ve double-checked the ID and secret. Is there something weird about how requests handles the form data encoding compared to what the Genesys endpoint expects? Or am I missing a header?

Any pointers would be appreciated.