From a541b3bb819b61de3809cd1c064a5a5a390cc4e5 Mon Sep 17 00:00:00 2001 From: Joona Hoikkala Date: Fri, 5 Jun 2015 13:12:36 +0300 Subject: [PATCH] Support both Python 2 & 3 base64 library --- spotipy/oauth2.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spotipy/oauth2.py b/spotipy/oauth2.py index 7784354..dc0de0c 100644 --- a/spotipy/oauth2.py +++ b/spotipy/oauth2.py @@ -62,8 +62,12 @@ class SpotifyClientCredentials(object): """Gets client credentials access token """ payload = { 'grant_type': 'client_credentials'} - auth_header = base64.b64encode(self.client_id + ':' + self.client_secret) - headers = {'Authorization': 'Basic %s' % auth_header} + 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} response = requests.post(self.OAUTH_TOKEN_URL, data=payload, headers=headers, verify=True)