mirror of
https://github.com/c0de-archive/spotipy.git
synced 2024-11-04 23:17:48 +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
|
||||
v2.310, January 05, 2015 -- Added session 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(
|
||||
name='spotipy',
|
||||
version='2.3.3',
|
||||
version='2.3.4',
|
||||
description='simple client for the Spotify Web API',
|
||||
author="@plamere",
|
||||
author_email="paul@echonest.com",
|
||||
|
@ -40,7 +40,7 @@ class Spotify(object):
|
||||
'''
|
||||
|
||||
trace = False # Enable tracing?
|
||||
max_get_retries = 5
|
||||
max_get_retries = 10
|
||||
|
||||
def __init__(self, auth=None, requests_session=True,
|
||||
client_credentials_manager=None):
|
||||
@ -115,16 +115,22 @@ class Spotify(object):
|
||||
if args:
|
||||
kwargs.update(args)
|
||||
retries = self.max_get_retries
|
||||
delay = 1
|
||||
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
|
||||
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:
|
||||
raise
|
||||
else:
|
||||
time.sleep(1)
|
||||
if self.trace:
|
||||
print ('retrying ...' + str(delay) + 'secs')
|
||||
time.sleep(delay)
|
||||
delay += 1
|
||||
else:
|
||||
raise
|
||||
|
||||
|
@ -118,7 +118,8 @@ class TestSpotipy(unittest.TestCase):
|
||||
def test_unauthenticated_post_fails(self):
|
||||
with self.assertRaises(SpotifyException) as cm:
|
||||
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):
|
||||
from requests import Session
|
||||
|
Loading…
Reference in New Issue
Block a user