From aae5f0ee80f0e36116b0f42e5f1f4a0aeed3f8dd Mon Sep 17 00:00:00 2001 From: Alexey V Paramonov Date: Sat, 29 Oct 2016 17:02:25 +0300 Subject: [PATCH] Added 'requests_timeout' option to tell Requests to stop waiting for a response after a given number of seconds --- spotipy/client.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spotipy/client.py b/spotipy/client.py index 8b15d9e..66071d2 100644 --- a/spotipy/client.py +++ b/spotipy/client.py @@ -45,7 +45,7 @@ class Spotify(object): max_get_retries = 10 def __init__(self, auth=None, requests_session=True, - client_credentials_manager=None): + client_credentials_manager=None, requests_timeout=None): ''' Create a Spotify API object. @@ -57,11 +57,13 @@ class Spotify(object): for performance reasons (connection pooling). :param client_credentials_manager: SpotifyClientCredentials object - + :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.requests_timeout = requests_timeout if isinstance(requests_session, requests.Session): self._session = requests_session @@ -83,6 +85,7 @@ class Spotify(object): def _internal_call(self, method, url, payload, params): args = dict(params=params) + args["timeout"] = self.requests_timeout if not url.startswith('http'): url = self.prefix + url headers = self._auth_headers()