mirror of
https://github.com/c0de-archive/spotipy.git
synced 2024-11-04 23:17:48 +00:00
Added automatic retry logic for gets
This commit is contained in:
parent
c8c44c1b28
commit
a78421a6e8
@ -6,8 +6,9 @@ v1.45, July 7, 2014 -- Support for related artists endpoint. Don't used
|
||||
cache auth codes when scope changes
|
||||
v1.50, August 14, 2014 -- Refactored util out of examples and into the main
|
||||
package
|
||||
v1.301, August 19, 2014 -- Upgraded version number to take precedence over
|
||||
v2.301, August 19, 2014 -- Upgraded version number to take precedence over
|
||||
previously botched release (sigh)
|
||||
v1.310, August 20, 2014 -- Added playlist replace and remove methods. Added auth
|
||||
v2.310, August 20, 2014 -- Added playlist replace and remove methods. Added auth
|
||||
tests. Improved API docs
|
||||
v1.310, January 05, 2015 -- Added session support
|
||||
v2.310, January 05, 2015 -- Added session support
|
||||
v2.3.1, March 28, 2015 -- auto retry support
|
||||
|
@ -65,3 +65,4 @@ If you have suggestions, bugs or other issues specific to this library, file the
|
||||
- v2.1.0 - October 25, 2014 -- Added support for new_releases and featured_playlists
|
||||
- v2.2.0 - November 15, 2014 -- Added support for user_playlist_tracks
|
||||
- v2.3.0 - January 5, 2015 -- Added session support added by akx.
|
||||
- v2.3.2 - March 31, 2015 -- Added auto retry logic
|
||||
|
2
setup.py
2
setup.py
@ -2,7 +2,7 @@ from setuptools import setup
|
||||
|
||||
setup(
|
||||
name='spotipy',
|
||||
version='2.3.0',
|
||||
version='2.3.2',
|
||||
description='simple client for the Spotify Web API',
|
||||
author="@plamere",
|
||||
author_email="paul@echonest.com",
|
||||
|
@ -6,6 +6,7 @@ import sys
|
||||
import base64
|
||||
import requests
|
||||
import json
|
||||
import time
|
||||
|
||||
''' A simple and thin Python library for the Spotify Web API
|
||||
'''
|
||||
@ -39,6 +40,7 @@ class Spotify(object):
|
||||
'''
|
||||
|
||||
trace = False # Enable tracing?
|
||||
max_get_retries = 5
|
||||
|
||||
def __init__(self, auth=None, requests_session=True,
|
||||
client_credentials_manager=None):
|
||||
@ -112,7 +114,19 @@ class Spotify(object):
|
||||
def _get(self, url, args=None, payload=None, **kwargs):
|
||||
if args:
|
||||
kwargs.update(args)
|
||||
return self._internal_call('GET', url, payload, kwargs)
|
||||
retries = self.max_get_retries
|
||||
while retries > 0:
|
||||
try:
|
||||
return self._internal_call('GET', url, payload, kwargs)
|
||||
except SpotifyException as e:
|
||||
if e.http_status >= 500 and e.http_status < 600:
|
||||
retries -= 1
|
||||
if retries < 0:
|
||||
raise
|
||||
else:
|
||||
time.sleep(1)
|
||||
else:
|
||||
raise
|
||||
|
||||
def _post(self, url, args=None, payload=None, **kwargs):
|
||||
if args:
|
||||
|
Loading…
Reference in New Issue
Block a user