Attempting to automate API calls for our CX-as-Code pipelines using Python requests. The goal is to fetch an OAuth2 access token via Client Credentials flow. The endpoint is https://api.mypurecloud.com/oauth/token. Sending a POST with grant_type=client_credentials and the credentials in the Authorization header. Getting a 401 Unauthorized response. The base64 encoding seems correct. Can you spot the issue in this snippet?
import requests, base64
creds = f"{client_id}:{client_secret}"
headers = {"Authorization": f"Basic {base64.b64encode(creds.encode()).decode()}", "Content-Type": "application/x-www-form-urlencoded"}
resp = requests.post(url, data={"grant_type": "client_credentials"}, headers=headers)