From d6a14bc83dd4a19945314b14d8bd6ed59a0c154e Mon Sep 17 00:00:00 2001 From: Joona Hoikkala Date: Fri, 5 Jun 2015 12:16:30 +0300 Subject: [PATCH] Urllib compatibility fix to support both python 2 & 3 --- spotipy/oauth2.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/spotipy/oauth2.py b/spotipy/oauth2.py index 7827fd4..bdcc0d8 100644 --- a/spotipy/oauth2.py +++ b/spotipy/oauth2.py @@ -1,13 +1,20 @@ from __future__ import print_function import base64 -import urllib.request, urllib.parse, urllib.error import requests import os import json import time import sys +# Workaround to support both python 2 & 3 +try: + import urllib.request, urllib.error + import urllib.parse as urllibparse +except ImportError: + import urllib as urllibparse + + class SpotifyOauthError(Exception): pass @@ -155,7 +162,7 @@ class SpotifyOAuth(object): if self.state: payload['state'] = self.state - urlparams = urllib.parse.urlencode(payload) + urlparams = urllibparse.urlencode(payload) return "%s?%s" % (self.OAUTH_AUTHORIZE_URL, urlparams)