spotify2tidal / spotify_to_tidal

A command line tool for importing your Spotify playlists into Tidal
GNU Affero General Public License v3.0
241 stars 44 forks source link

Authorization Failure #56

Closed PacifistPickle closed 1 month ago

PacifistPickle commented 1 month ago

I'm getting an authorization failure when trying to open the Spotify session. I followed the ReadMe on setting up an app on developer.spotify.com and changing the config.

Error: gio: https://accounts.spotify.com/authorize?client_id=bf0154e1300a44318a4f2fa2720d02c3&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8888%2Fcallback&scope=playlist-read-private: Operation not supported

Traceback: (the code hangs indefinitely on this error)

^CTraceback (most recent call last):
File "/home/developer/spotify_to_tidal/venv/bin/spotify_to_tidal", line 8, in <module>
    sys.exit(main())
    ^^^^^^
File "/home/developer/spotify_to_tidal/src/spotify_to_tidal/__main__.py", line 17, in main
    spotify_session = _auth.open_spotify_session(config['spotify'])
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/developer/spotify_to_tidal/src/spotify_to_tidal/auth.py", line 24, in open_spotify_session
    credentials_manager.get_access_token(as_dict=False)
File "/home/developer/spotify_to_tidal/venv/lib/python3.12/site-packages/spotipy/oauth2.py", line 535, in get_access_token
    "code": code or self.get_auth_response(),
    ^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/developer/spotify_to_tidal/venv/lib/python3.12/site-packages/spotipy/oauth2.py", line 490, in get_auth_response
    return self._get_auth_response_local_server(redirect_port)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/developer/spotify_to_tidal/venv/lib/python3.12/site-packages/spotipy/oauth2.py", line 459, in _get_auth_response_local_server
    server.handle_request()
File "/usr/lib/python3.12/socketserver.py", line 297, in handle_request
    if selector.select(timeout):
    ^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/selectors.py", line 415, in select
    fd_event_list = self._selector.poll(timeout)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Config: (with client_secret and username redacted)

spotify:
  client_id: bf0154e1300a44318a4f2fa2720d02c3
  client_secret: <secret key>
  username: <name>
  redirect_uri: http://localhost:8888/callback

# uncomment this block if you want to only sync specific playlist IDs
#sync_playlists:
#  - spotify_id: 1ABCDEqsABCD6EaABCDa0a
#    tidal_id: a0b1234-0a1b-012a-abcd-a1b234c5d6d7

# uncomment this block if you want to sync all playlists in the account with some exceptions
#excluded_playlists:
#  - spotify:playlist:1ABCDEqsABCD6EaABCDa0a

# increasing these parameters should increase the search speed, while decreasing reduces likelihood of 429 errors
max_concurrency: 10 # max concurrent connections at any given time
rate_limit:      12 # max sustained connections per second

Spotify App Settings:

Redirect URIs: http://localhost:8888/callback
APIs used: Web API

I figure I must be missing something, googling the issues have just led me in vague circles. Some Spotify forums suggest I need to allow the scope of playlist-read-private in my app, but I am unable to find such a setting. Regardless of what I'm doing wrong, might be best to handle this scenario to alert the user to the issue instead of hanging.

Thanks

timrae commented 1 month ago

The playlist-read-private scope is requested by the app here, you don't need to "add" it anywhere. But when you run the script, I believe a browser window should open the first time you run it, where you need to grant the app access to that permission. Did you get a Spotify window popup and did you grant the permission?

All I can think of off the top of my head is maybe you're trying to run this on a headless server (not supported, though you should be able to find a workaround for this), or maybe you denied access to the app accidentally when the window popped up?

There should be a file .cache-{spotify_username} which you can try deleting, this might make the authorisation process start again. Tbh I'm not too sure, as this is an implementation detail of the spotipy library we use. Also make sure the username matches what you see in the top right corner of https://developer.spotify.com/

PacifistPickle commented 1 month ago

Ah I see now. I did not get a browser window to open automatically. I'll bet this is a symptom of running in wsl because I'm too lazy to shut down and boot my Linux partition. I was able to circumvent this issue by copying the address printed to the command line and pasting it into the browser.