diff --git a/spotipy/client.py b/spotipy/client.py index 0d13fa0..4956dfb 100644 --- a/spotipy/client.py +++ b/spotipy/client.py @@ -51,7 +51,7 @@ class Spotify(object): max_get_retries = 10 def __init__(self, auth=None, requests_session=True, - client_credentials_manager=None, requests_timeout=None): + client_credentials_manager=None, proxies=None, requests_timeout=None): ''' Create a Spotify API object. @@ -63,12 +63,15 @@ class Spotify(object): for performance reasons (connection pooling). :param client_credentials_manager: SpotifyClientCredentials object + :param proxies: + Definition of proxies (optional) :param requests_timeout: Tell Requests to stop waiting for a response after a given number of seconds ''' self.prefix = 'https://api.spotify.com/v1/' self._auth = auth self.client_credentials_manager = client_credentials_manager + self.proxies = proxies self.requests_timeout = requests_timeout if isinstance(requests_session, requests.Session): @@ -102,7 +105,7 @@ class Spotify(object): if self.trace_out: print(url) - r = self._session.request(method, url, headers=headers, **args) + r = self._session.request(method, url, headers=headers, proxies=self.proxies, **args) if self.trace: # pragma: no cover print() diff --git a/spotipy/oauth2.py b/spotipy/oauth2.py index f21a669..7303ff0 100644 --- a/spotipy/oauth2.py +++ b/spotipy/oauth2.py @@ -23,7 +23,7 @@ class SpotifyOauthError(Exception): class SpotifyClientCredentials(object): OAUTH_TOKEN_URL = 'https://accounts.spotify.com/api/token' - def __init__(self, client_id=None, client_secret=None): + def __init__(self, client_id=None, client_secret=None, proxies=None): """ You can either provid a client_id and client_secret to the constructor or set SPOTIPY_CLIENT_ID and SPOTIPY_CLIENT_SECRET @@ -44,6 +44,7 @@ class SpotifyClientCredentials(object): self.client_id = client_id self.client_secret = client_secret self.token_info = None + self.proxies = proxies def get_access_token(self): """ @@ -70,7 +71,7 @@ class SpotifyClientCredentials(object): headers = {'Authorization': 'Basic %s' % auth_header} response = requests.post(self.OAUTH_TOKEN_URL, data=payload, - headers=headers, verify=True) + headers=headers, verify=True, proxies=self.proxies) if response.status_code is not 200: raise SpotifyOauthError(response.reason) token_info = response.json() @@ -210,7 +211,7 @@ class SpotifyOAuth(object): headers = {'Authorization': 'Basic %s' % auth_header} response = requests.post(self.OAUTH_TOKEN_URL, data=payload, - headers=headers, verify=True) + headers=headers, verify=True, proxies=self.proxies) if response.status_code is not 200: raise SpotifyOauthError(response.reason) token_info = response.json() @@ -238,7 +239,7 @@ class SpotifyOAuth(object): headers = {'Authorization': 'Basic %s' % auth_header} response = requests.post(self.OAUTH_TOKEN_URL, data=payload, - headers=headers) + headers=headers, proxies=self.proxies) if response.status_code != 200: if False: # debugging code print('headers', headers)