spotipy-dev / spotipy

A light weight Python library for the Spotify Web API
http://spotipy.readthedocs.org
MIT License
5.04k stars 959 forks source link

User not approved for app / 403, code:-1 - https://api.spotify.com/v1/me/: error, reason: None #688

Closed TiceWise closed 3 years ago

TiceWise commented 3 years ago

Describe the bug Since a recent 'Spotify for Developers'-update (see "Improving the developer and user experience for third-party apps" May 27, 2021), users need to be added in the 'Spotify for Developers'-dashboard.

I discovered the bug after a successful sign in with a different account, but the the simple 'spotify.me()' call raised the unclear error: "spotipy.exceptions.SpotifyException: http status: 403, code:-1 - https://api.spotify.com/v1/me/: error, reason: None"

After diving in client.py I noticed the actual response message was b"User not approved for app". Searching further I found the news-post mentioned earlier.

Your code

spotify = spotipy.Spotify(auth_manager=auth_manager)
user = spotify.me()

Expected behavior I think it would be better to return the "User not approved for app" as error, instead of the reason: None. Possibly even with a referral to the Spotify developer dashboard to add users.

Output

Traceback (most recent call last):
  File "/Users/***/.pyenv/versions/3.9.5/lib/python3.9/site-packages/spotipy/client.py", line 245, in _internal_call
    response.raise_for_status()
  File "/Users/***/.pyenv/versions/3.9.5/lib/python3.9/site-packages/requests/models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://api.spotify.com/v1/me/

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/***/.pyenv/versions/3.9.5/lib/python3.9/site-packages/flask/app.py", line 2088, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/***/.pyenv/versions/3.9.5/lib/python3.9/site-packages/flask/app.py", line 2073, in wsgi_app
    response = self.handle_exception(e)
  File "/Users/***/.pyenv/versions/3.9.5/lib/python3.9/site-packages/flask/app.py", line 2070, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/***/.pyenv/versions/3.9.5/lib/python3.9/site-packages/flask/app.py", line 1515, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/***/.pyenv/versions/3.9.5/lib/python3.9/site-packages/flask/app.py", line 1513, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/***/.pyenv/versions/3.9.5/lib/python3.9/site-packages/flask/app.py", line 1499, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/Users/***.../***/app.py", line 167, in login
    user = spotify.me()
  File "/Users/***/.pyenv/versions/3.9.5/lib/python3.9/site-packages/spotipy/client.py", line 1161, in me
    return self._get("me/")
  File "/Users/***/.pyenv/versions/3.9.5/lib/python3.9/site-packages/spotipy/client.py", line 291, in _get
    return self._internal_call("GET", url, payload, kwargs)
  File "/Users/***/.pyenv/versions/3.9.5/lib/python3.9/site-packages/spotipy/client.py", line 261, in _internal_call
    raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 403, code:-1 - https://api.spotify.com/v1/me/:
 error, reason: None

Environment:

Additional context "Improving the developer and user experience for third-party apps"

stephanebruckert commented 3 years ago

Fixed by @Peter-Schorn's PR, thanks. Will release soon