diff --git a/CHANGELOG.md b/CHANGELOG.md index 534f00d..897f852 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased -// Add your changes here and then delete this line +### Fixed + +- UnboundLocalError when a request fails ( #571 ) + ## [2.16.0] - 2020-09-16 diff --git a/spotipy/client.py b/spotipy/client.py index 6d4ff07..8ea9b26 100644 --- a/spotipy/client.py +++ b/spotipy/client.py @@ -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,7 +264,8 @@ class Spotify(object): reason=reason, headers=response.headers, ) - except requests.exceptions.RetryError: + except requests.exceptions.RetryError as retry_error: + response = retry_error.response logger.error('Max Retries reached') raise SpotifyException( 599,