mirror of
https://github.com/c0de-archive/spotipy.git
synced 2025-01-07 23:22:49 +00:00
Fixed problem with retry support
This commit is contained in:
parent
1b75562ce4
commit
b96fd5ca8d
@ -12,3 +12,4 @@ v2.310, August 20, 2014 -- Added playlist replace and remove methods. Added auth
|
|||||||
tests. Improved API docs
|
tests. Improved API docs
|
||||||
v2.310, January 05, 2015 -- Added session support
|
v2.310, January 05, 2015 -- Added session support
|
||||||
v2.3.1, March 28, 2015 -- auto retry support
|
v2.3.1, March 28, 2015 -- auto retry support
|
||||||
|
v2.3.3, April 28, 2015 -- fixed bug in auto retry support
|
||||||
|
2
setup.py
2
setup.py
@ -2,7 +2,7 @@ from setuptools import setup
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='spotipy',
|
name='spotipy',
|
||||||
version='2.3.3',
|
version='2.3.4',
|
||||||
description='simple client for the Spotify Web API',
|
description='simple client for the Spotify Web API',
|
||||||
author="@plamere",
|
author="@plamere",
|
||||||
author_email="paul@echonest.com",
|
author_email="paul@echonest.com",
|
||||||
|
@ -40,7 +40,7 @@ class Spotify(object):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
trace = False # Enable tracing?
|
trace = False # Enable tracing?
|
||||||
max_get_retries = 5
|
max_get_retries = 10
|
||||||
|
|
||||||
def __init__(self, auth=None, requests_session=True,
|
def __init__(self, auth=None, requests_session=True,
|
||||||
client_credentials_manager=None):
|
client_credentials_manager=None):
|
||||||
@ -115,16 +115,22 @@ class Spotify(object):
|
|||||||
if args:
|
if args:
|
||||||
kwargs.update(args)
|
kwargs.update(args)
|
||||||
retries = self.max_get_retries
|
retries = self.max_get_retries
|
||||||
|
delay = 1
|
||||||
while retries > 0:
|
while retries > 0:
|
||||||
try:
|
try:
|
||||||
return self._internal_call('GET', url, payload, kwargs)
|
return self._internal_call('GET', url, payload, kwargs)
|
||||||
except SpotifyException as e:
|
except SpotifyException as e:
|
||||||
if e.http_status >= 500 and e.http_status < 600:
|
retries -= 1
|
||||||
retries -= 1
|
status = e.http_status
|
||||||
|
# 429 means we hit a rate limit, backoff
|
||||||
|
if status == 429 or status >= 500 and status < 600:
|
||||||
if retries < 0:
|
if retries < 0:
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
time.sleep(1)
|
if self.trace:
|
||||||
|
print ('retrying ...' + str(delay) + 'secs')
|
||||||
|
time.sleep(delay)
|
||||||
|
delay += 1
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
@ -118,7 +118,8 @@ class TestSpotipy(unittest.TestCase):
|
|||||||
def test_unauthenticated_post_fails(self):
|
def test_unauthenticated_post_fails(self):
|
||||||
with self.assertRaises(SpotifyException) as cm:
|
with self.assertRaises(SpotifyException) as cm:
|
||||||
self.spotify.user_playlist_create("spotify", "Best hits of the 90s")
|
self.spotify.user_playlist_create("spotify", "Best hits of the 90s")
|
||||||
self.assertEqual(cm.exception.http_status, 401)
|
self.assertTrue(cm.exception.http_status == 401 or
|
||||||
|
cm.exception.http_status == 403)
|
||||||
|
|
||||||
def test_custom_requests_session(self):
|
def test_custom_requests_session(self):
|
||||||
from requests import Session
|
from requests import Session
|
||||||
|
Loading…
Reference in New Issue
Block a user