mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-06-19 01:03:53 +00:00
* Fix plamere/spotipy#571, plamere/spotipy#581 * Add integration test for reaching max retries * Update tests/integration/test_non_user_endpoints.py Co-authored-by: Stéphane Bruckert <contact@stephanebruckert.com> * Update CHANGELOG.md, integration test mock data Co-authored-by: Stéphane Bruckert <contact@stephanebruckert.com>
This commit is contained in:
parent
76b640ae1e
commit
4bb42598e1
@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
// Add your changes here and then delete this line
|
### Fixed
|
||||||
|
|
||||||
|
- SpotifyException now thrown when a request fails & has no response ( fixes #571, #581 )
|
||||||
|
|
||||||
## [2.16.0] - 2020-09-16
|
## [2.16.0] - 2020-09-16
|
||||||
|
|
||||||
|
|||||||
@ -243,7 +243,8 @@ class Spotify(object):
|
|||||||
|
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
results = response.json()
|
results = response.json()
|
||||||
except requests.exceptions.HTTPError:
|
except requests.exceptions.HTTPError as http_error:
|
||||||
|
response = http_error.response
|
||||||
try:
|
try:
|
||||||
msg = response.json()["error"]["message"]
|
msg = response.json()["error"]["message"]
|
||||||
except (ValueError, KeyError):
|
except (ValueError, KeyError):
|
||||||
@ -263,13 +264,18 @@ class Spotify(object):
|
|||||||
reason=reason,
|
reason=reason,
|
||||||
headers=response.headers,
|
headers=response.headers,
|
||||||
)
|
)
|
||||||
except requests.exceptions.RetryError:
|
except requests.exceptions.RetryError as retry_error:
|
||||||
|
request = retry_error.request
|
||||||
logger.error('Max Retries reached')
|
logger.error('Max Retries reached')
|
||||||
|
try:
|
||||||
|
reason = retry_error.args[0].reason
|
||||||
|
except (IndexError, AttributeError):
|
||||||
|
reason = None
|
||||||
raise SpotifyException(
|
raise SpotifyException(
|
||||||
599,
|
599,
|
||||||
-1,
|
-1,
|
||||||
"%s:\n %s" % (response.url, "Max Retries"),
|
"%s:\n %s" % (request.path_url, "Max Retries"),
|
||||||
headers=response.headers,
|
reason=reason
|
||||||
)
|
)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
results = None
|
results = None
|
||||||
|
|||||||
@ -240,6 +240,20 @@ 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):
|
||||||
|
spotify_no_retry = Spotify(
|
||||||
|
client_credentials_manager=SpotifyClientCredentials(),
|
||||||
|
retries=0)
|
||||||
|
i = 0
|
||||||
|
while i < 100:
|
||||||
|
try:
|
||||||
|
spotify_no_retry.search(q='foo')
|
||||||
|
except spotipy.exceptions.SpotifyException as e:
|
||||||
|
self.assertIsInstance(e, spotipy.exceptions.SpotifyException)
|
||||||
|
return
|
||||||
|
i += 1
|
||||||
|
self.fail()
|
||||||
|
|
||||||
def test_album_search(self):
|
def test_album_search(self):
|
||||||
results = self.spotify.search(q='weezer pinkerton', type='album')
|
results = self.spotify.search(q='weezer pinkerton', type='album')
|
||||||
self.assertTrue('albums' in results)
|
self.assertTrue('albums' in results)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user