Urllib compatibility fix to support both python 2 & 3

This commit is contained in:
Joona Hoikkala 2015-06-05 12:16:30 +03:00
parent d08f7a82dc
commit d6a14bc83d

View File

@ -1,13 +1,20 @@
from __future__ import print_function from __future__ import print_function
import base64 import base64
import urllib.request, urllib.parse, urllib.error
import requests import requests
import os import os
import json import json
import time import time
import sys 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): class SpotifyOauthError(Exception):
pass pass
@ -155,7 +162,7 @@ class SpotifyOAuth(object):
if self.state: if self.state:
payload['state'] = self.state payload['state'] = self.state
urlparams = urllib.parse.urlencode(payload) urlparams = urllibparse.urlencode(payload)
return "%s?%s" % (self.OAUTH_AUTHORIZE_URL, urlparams) return "%s?%s" % (self.OAUTH_AUTHORIZE_URL, urlparams)