Python : 3.9
import requests
import base64
import json
client_id = '<Client ID>'
client_secret = '<Client Secret>'
endpoint = 'https://accounts.spotify.com/api/token'
encoded = base64.b64encode(f'{client_id}:{client_secret}'.encode('utf-8')).decode('ascii')
headers = {'Authorization': f'Basic {encoded}'}
payload = {'grant_type': 'client_credentials'}
response = requests.post(endpoint, data=payload, headers=headers)
# print(json.loads(response.text))
access_token = json.loads(response.text)['access_token']
print(access_token)