mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-06-19 09:13:53 +00:00
* Retry for POST, PUT and DELETE, fixes #577 * Lint
This commit is contained in:
parent
275cd7ea89
commit
dd948c49d9
@ -9,13 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- playlist_tracks example code no longer prints extra characters on final loop iteration
|
- playlist_tracks example code no longer prints extra characters on final loop iteration
|
||||||
- SpotifyException now thrown when a request fails & has no response ( fixes #571, #581 )
|
- SpotifyException now thrown when a request fails & has no response ( fixes #571, #581 )
|
||||||
- Added scope, 'playlist-read-private', to examples that access user playlists using the spotipy api: current_user_playlists() (fixes #591)
|
- Added scope, 'playlist-read-private', to examples that access user playlists using the spotipy api: current_user_playlists() (fixes #591)
|
||||||
|
- Enable retries for POST, DELETE, PUT
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- both inline and starting import lists are sorted using `isort` module
|
- both inline and starting import lists are sorted using `isort` module
|
||||||
|
- changed exception Max Retries exception code from 599 to 429
|
||||||
|
|
||||||
## [2.16.0] - 2020-09-16
|
## [2.16.0] - 2020-09-16
|
||||||
|
|
||||||
|
|||||||
@ -194,6 +194,7 @@ class Spotify(object):
|
|||||||
total=self.retries,
|
total=self.retries,
|
||||||
connect=None,
|
connect=None,
|
||||||
read=False,
|
read=False,
|
||||||
|
method_whitelist=frozenset(['GET', 'POST', 'PUT', 'DELETE']),
|
||||||
status=self.status_retries,
|
status=self.status_retries,
|
||||||
backoff_factor=self.backoff_factor,
|
backoff_factor=self.backoff_factor,
|
||||||
status_forcelist=self.status_forcelist)
|
status_forcelist=self.status_forcelist)
|
||||||
@ -272,7 +273,7 @@ class Spotify(object):
|
|||||||
except (IndexError, AttributeError):
|
except (IndexError, AttributeError):
|
||||||
reason = None
|
reason = None
|
||||||
raise SpotifyException(
|
raise SpotifyException(
|
||||||
599,
|
429,
|
||||||
-1,
|
-1,
|
||||||
"%s:\n %s" % (request.path_url, "Max Retries"),
|
"%s:\n %s" % (request.path_url, "Max Retries"),
|
||||||
reason=reason
|
reason=reason
|
||||||
|
|||||||
@ -11,9 +11,5 @@ def get_spotify_playlist(spotify_object, playlist_name, username):
|
|||||||
playlists = spotify_object.next(playlists)
|
playlists = spotify_object.next(playlists)
|
||||||
|
|
||||||
|
|
||||||
def create_spotify_playlist(spotify_object, playlist_name, username):
|
|
||||||
return spotify_object.user_playlist_create(username, playlist_name)
|
|
||||||
|
|
||||||
|
|
||||||
def get_as_base64(url):
|
def get_as_base64(url):
|
||||||
return base64.b64encode(requests.get(url).content).decode("utf-8")
|
return base64.b64encode(requests.get(url).content).decode("utf-8")
|
||||||
|
|||||||
@ -240,7 +240,7 @@ class AuthTestSpotipy(unittest.TestCase):
|
|||||||
self.assertRaises((requests.exceptions.Timeout, requests.exceptions.ConnectionError),
|
self.assertRaises((requests.exceptions.Timeout, requests.exceptions.ConnectionError),
|
||||||
lambda: sp.search(q='my*', type='track'))
|
lambda: sp.search(q='my*', type='track'))
|
||||||
|
|
||||||
def test_max_retries_reached(self):
|
def test_max_retries_reached_get(self):
|
||||||
spotify_no_retry = Spotify(
|
spotify_no_retry = Spotify(
|
||||||
client_credentials_manager=SpotifyClientCredentials(),
|
client_credentials_manager=SpotifyClientCredentials(),
|
||||||
retries=0)
|
retries=0)
|
||||||
@ -248,8 +248,9 @@ class AuthTestSpotipy(unittest.TestCase):
|
|||||||
while i < 100:
|
while i < 100:
|
||||||
try:
|
try:
|
||||||
spotify_no_retry.search(q='foo')
|
spotify_no_retry.search(q='foo')
|
||||||
except spotipy.exceptions.SpotifyException as e:
|
except SpotifyException as e:
|
||||||
self.assertIsInstance(e, spotipy.exceptions.SpotifyException)
|
self.assertIsInstance(e, SpotifyException)
|
||||||
|
self.assertEqual(e.http_status, 429)
|
||||||
return
|
return
|
||||||
i += 1
|
i += 1
|
||||||
self.fail()
|
self.fail()
|
||||||
|
|||||||
@ -52,12 +52,11 @@ class SpotipyPlaylistApiTest(unittest.TestCase):
|
|||||||
token = prompt_for_user_token(cls.username, scope=scope)
|
token = prompt_for_user_token(cls.username, scope=scope)
|
||||||
|
|
||||||
cls.spotify = Spotify(auth=token)
|
cls.spotify = Spotify(auth=token)
|
||||||
|
cls.spotify_no_retry = Spotify(auth=token, retries=0)
|
||||||
cls.new_playlist_name = 'spotipy-playlist-test'
|
cls.new_playlist_name = 'spotipy-playlist-test'
|
||||||
cls.new_playlist = helpers.get_spotify_playlist(
|
cls.new_playlist = helpers.get_spotify_playlist(
|
||||||
cls.spotify, cls.new_playlist_name, cls.username) or \
|
cls.spotify, cls.new_playlist_name, cls.username) or \
|
||||||
helpers.create_spotify_playlist(
|
cls.spotify.user_playlist_create(cls.username, cls.new_playlist_name)
|
||||||
cls.spotify, cls.new_playlist_name, cls.username)
|
|
||||||
cls.new_playlist_uri = cls.new_playlist['uri']
|
cls.new_playlist_uri = cls.new_playlist['uri']
|
||||||
|
|
||||||
def test_user_playlists(self):
|
def test_user_playlists(self):
|
||||||
@ -120,6 +119,19 @@ class SpotipyPlaylistApiTest(unittest.TestCase):
|
|||||||
pl = self.spotify.playlist(self.new_playlist['id'])
|
pl = self.spotify.playlist(self.new_playlist['id'])
|
||||||
self.assertEqual(pl["tracks"]["total"], 0)
|
self.assertEqual(pl["tracks"]["total"], 0)
|
||||||
|
|
||||||
|
def test_max_retries_reached_post(self):
|
||||||
|
i = 0
|
||||||
|
while i < 100:
|
||||||
|
try:
|
||||||
|
self.spotify_no_retry.playlist_change_details(
|
||||||
|
self.new_playlist['id'], description="test")
|
||||||
|
except SpotifyException as e:
|
||||||
|
self.assertIsInstance(e, SpotifyException)
|
||||||
|
self.assertEqual(e.http_status, 429)
|
||||||
|
return
|
||||||
|
i += 1
|
||||||
|
self.fail()
|
||||||
|
|
||||||
def test_playlist_add_items(self):
|
def test_playlist_add_items(self):
|
||||||
# add tracks to playlist
|
# add tracks to playlist
|
||||||
self.spotify.playlist_add_items(
|
self.spotify.playlist_add_items(
|
||||||
@ -223,7 +235,7 @@ class SpotipyLibraryApiTests(unittest.TestCase):
|
|||||||
new_total = tracks['total']
|
new_total = tracks['total']
|
||||||
self.assertEqual(new_total - total, len(self.four_tracks))
|
self.assertEqual(new_total - total, len(self.four_tracks))
|
||||||
|
|
||||||
tracks = self.spotify.current_user_saved_tracks_delete(
|
self.spotify.current_user_saved_tracks_delete(
|
||||||
self.four_tracks)
|
self.four_tracks)
|
||||||
tracks = self.spotify.current_user_saved_tracks()
|
tracks = self.spotify.current_user_saved_tracks()
|
||||||
new_total = tracks['total']
|
new_total = tracks['total']
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user