Fixed UnboundLocalError / AttributeError #571, #581 (#583)

* 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:
CallumandStéphane Bruckert authored and GitHub committed 2020-10-07 09:00:45 +01:00
1 parent 76b640ae1e
commit 4bb42598e1
3 files changed
+27 -5

No files matched your search

+10 -4
View File
@@ -243,7 +243,8 @@ class Spotify(object):
response.raise_for_status()
results = response.json()
except requests.exceptions.HTTPError:
except requests.exceptions.HTTPError as http_error:
response = http_error.response
try:
msg = response.json()["error"]["message"]
except (ValueError, KeyError):
@@ -263,13 +264,18 @@ class Spotify(object):
reason=reason,
headers=response.headers,
)
except requests.exceptions.RetryError:
except requests.exceptions.RetryError as retry_error:
request = retry_error.request
logger.error('Max Retries reached')
try:
reason = retry_error.args[0].reason
except (IndexError, AttributeError):
reason = None
raise SpotifyException(
599,
-1,
"%s:\n %s" % (response.url, "Max Retries"),
headers=response.headers,
"%s:\n %s" % (request.path_url, "Max Retries"),
reason=reason
)
except ValueError:
results = None