dupontgu / retro-ipod-spotify-client

The software that powers the sPot: a 4th generation "Click Wheel" iPod with a full Spotify client.
Apache License 2.0
913 stars 90 forks source link

Can't connect to Spotify API #6

Closed sguldemond closed 3 years ago

sguldemond commented 3 years ago

Hey, I saw your video on YouTube. Really cool project! I remember my iPod mini fondly :) I remember flashing some alternative OS on it as a kid, probably breaking it with that, but that was so cool. I would write notes on it to cheat on a topography test :smile:

So I wanted to take a look at your sPod interface. But I can't seem to connect to the Spotify API.

I set the spotipy variables correctly I think:

export SPOTIPY_CLIENT_ID=123 (not my real id)
export SPOTIPY_CLIENT_SECRET=abc (not my real secret)
export SPOTIPY_REDIRECT_URI=http://foo.bar

But getting stuck after pasting the redirect URL:

$ python spotifypod.py    
Couldn't read cache at: .cache
Couldn't read cache at: .cache
Enter the URL you were redirected to: http://foo.bar/?code=AQB95fJ1ctCgK2sst8VCmMvxGQOdU878Ob6l9hHodiv54CICwbVFXw8ZLz00chlVDl34mCU-udeEdWSsrw5_rxW3RGVN45k-iMq-0AuBcLshVbIet-h6DROk17QiXrb8KbJR9IjeXGFjPCMBn2V4q_gOye-EXU6YxMbDKQI91PIHmsa-q54zs5sME8nMnANU26uCKYOCxg
Enter the URL you were redirected to: HTTP Error for GET to https://api.spotify.com/v1/me/player/devices returned 401 due to Permissions missing
Traceback (most recent call last):
  File "/home/stan/Misc/retro-ipod-spotify-client/frontend/venv/lib/python3.8/site-packages/spotipy/client.py", line 245, in _internal_call
    response.raise_for_status()
  File "/home/stan/Misc/retro-ipod-spotify-client/frontend/venv/lib/python3.8/site-packages/requests/models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.spotify.com/v1/me/player/devices

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "spotifypod.py", line 12, in <module>
    from view_model import *
  File "/home/stan/Misc/retro-ipod-spotify-client/frontend/view_model.py", line 16, in <module>
    spotify_manager.refresh_devices()
  File "/home/stan/Misc/retro-ipod-spotify-client/frontend/spotify_manager.py", line 129, in refresh_devices
    results = sp.devices()
  File "/home/stan/Misc/retro-ipod-spotify-client/frontend/venv/lib/python3.8/site-packages/spotipy/client.py", line 1633, in devices
    return self._get("me/player/devices")
  File "/home/stan/Misc/retro-ipod-spotify-client/frontend/venv/lib/python3.8/site-packages/spotipy/client.py", line 291, in _get
    return self._internal_call("GET", url, payload, kwargs)
  File "/home/stan/Misc/retro-ipod-spotify-client/frontend/venv/lib/python3.8/site-packages/spotipy/client.py", line 261, in _internal_call
    raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 401, code:-1 - https://api.spotify.com/v1/me/player/devices:
 Permissions missing, reason: None

Do you have any idea what could be wrong here? The .cache file is being created and populated correctly as far as I can see.

ElCapitanDre commented 3 years ago

Hey @sguldemond I've had this problem too. It's caused by the scope. Apparently it needs some more permissions before you can get it to work. You can check what scopes are available to use here: https://developer.spotify.com/documentation/general/guides/scopes/

I think that for devices it's this one - user-read-playback-state -, but experiment until you get it to work

Good luck

Shogan commented 3 years ago

Yes 401 responses come back from Spotify if the action you're requesting is not handled by your scope selection. I also ran into this, fixed on my fork version here: https://github.com/Shogan/retro-ipod-spotify-client/commit/5629d9814ea90e5800b61c8dddf5b2b756f32633