Support both Python 2 & 3 base64 library

This commit is contained in:
Joona Hoikkala 2015-06-05 13:12:36 +03:00
parent a3a68be7bc
commit a541b3bb81

View File

@ -62,6 +62,10 @@ class SpotifyClientCredentials(object):
"""Gets client credentials access token """
payload = { 'grant_type': 'client_credentials'}
if sys.version_info[0] >= 3: # Python 3
auth_header = base64.b64encode(str(self.client_id + ':' + self.client_secret).encode())
headers = {'Authorization': 'Basic %s' % auth_header.decode()}
else: # Python 2
auth_header = base64.b64encode(self.client_id + ':' + self.client_secret)
headers = {'Authorization': 'Basic %s' % auth_header}