Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnboundLocalError: local variable 'response' referenced before assignment #571

Closed
peterbe opened this issue Sep 5, 2020 · 1 comment · Fixed by #583
Closed

UnboundLocalError: local variable 'response' referenced before assignment #571

peterbe opened this issue Sep 5, 2020 · 1 comment · Fixed by #583
Labels

Comments

@peterbe
Copy link
Contributor

peterbe commented Sep 5, 2020

Describe the bug
If something goes wrong in self._session.request() the variable response will never be set. Leading to a
UnboundLocalError: local variable 'response' referenced before assignment

Your code
Sorry.
Error from my Rollbar:
Screen Shot 2020-09-05 at 9 51 41 AM

Expected behavior
Requests fail and that's fine. Judging from skimming the code, it's trying to package a message to go with raising a SpotifyException but it's failing to do so.

Output
Paste and format errors (with complete stacktrace) or logs. Make sure to remove sensitive information.

Environment:

  • spotipy version: spotipy==2.13.0

Additional context
Relying on UnboundLocalError from a caller isn't nice. If it was SpotifyException I could do something like this:

from spotipy.exceptions import SpotifyException

try:
    something_that_calls_spotipy(...)
except SpotifyException as err:
    logger.warning("Oh no. Spotify exception...")
@peterbe peterbe added the bug label Sep 5, 2020
stephanebruckert pushed a commit that referenced this issue Oct 2, 2020
@stephanebruckert
Copy link
Member

Should be fixed by #580

stephanebruckert added a commit that referenced this issue Oct 6, 2020
stephanebruckert added a commit that referenced this issue Oct 6, 2020
Quizz1Cal added a commit to Quizz1Cal/spotipy that referenced this issue Oct 6, 2020
stephanebruckert added a commit that referenced this issue Oct 7, 2020
* Fix #571, #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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants