sigma67 / spotify_to_ytmusic

Clone a Spotify playlist to YouTube Music
MIT License
949 stars 72 forks source link

re-running setup for second account fails #85

Open The-Spartan opened 10 months ago

The-Spartan commented 10 months ago

Installed via pip install spotify_to_ytmusic, command is spotify_to_ytmusic all [user]

spotify_to_ytmusic setup works flawlessly. Running ytmusicapi 1,4,1m changing to 1.4.0 does not alleviate the issue

Client ID and secrets are correct as have re-entered them with re-rolled creds.

Traceback (most recent call last):
  File "C:\Users\Chris\AppData\Local\Programs\Python\Python310\lib\site-packages\spotipy\oauth2.py", line 588, in refresh_access_token
    response.raise_for_status()
  File "C:\Users\Chris\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://accounts.spotify.com/api/token

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Chris\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\Chris\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\Chris\AppData\Local\Programs\Python\Python310\Scripts\spotify_to_ytmusic.exe\__main__.py", line 7, in <module>
  File "C:\Users\Chris\AppData\Local\Programs\Python\Python310\lib\site-packages\spotify_to_ytmusic\main.py", line 86, in main
    args.func(args)
  File "C:\Users\Chris\AppData\Local\Programs\Python\Python310\lib\site-packages\spotify_to_ytmusic\controllers.py", line 34, in all
    pl = spotify.getUserPlaylists(args.user)
  File "C:\Users\Chris\AppData\Local\Programs\Python\Python310\lib\site-packages\spotify_to_ytmusic\spotify.py", line 70, in getUserPlaylists
    pl = self.api.user_playlists(user)["items"]
  File "C:\Users\Chris\AppData\Local\Programs\Python\Python310\lib\site-packages\spotipy\client.py", line 797, in user_playlists
    return self._get(
  File "C:\Users\Chris\AppData\Local\Programs\Python\Python310\lib\site-packages\spotipy\client.py", line 323, in _get
    return self._internal_call("GET", url, payload, kwargs)
  File "C:\Users\Chris\AppData\Local\Programs\Python\Python310\lib\site-packages\spotipy\client.py", line 247, in _internal_call
    headers = self._auth_headers()
  File "C:\Users\Chris\AppData\Local\Programs\Python\Python310\lib\site-packages\spotipy\client.py", line 238, in _auth_headers
    token = self.auth_manager.get_access_token(as_dict=False)
  File "C:\Users\Chris\AppData\Local\Programs\Python\Python310\lib\site-packages\spotipy\oauth2.py", line 525, in get_access_token
    token_info = self.validate_token(self.cache_handler.get_cached_token())
  File "C:\Users\Chris\AppData\Local\Programs\Python\Python310\lib\site-packages\spotipy\oauth2.py", line 380, in validate_token
    token_info = self.refresh_access_token(
  File "C:\Users\Chris\AppData\Local\Programs\Python\Python310\lib\site-packages\spotipy\oauth2.py", line 596, in refresh_access_token
    self._handle_oauth_error(http_error)
  File "C:\Users\Chris\AppData\Local\Programs\Python\Python310\lib\site-packages\spotipy\oauth2.py", line 146, in _handle_oauth_error
    raise SpotifyOauthError(
spotipy.oauth2.SpotifyOauthError: error: invalid_client, error_description: Invalid client

any ideas?

sigma67 commented 10 months ago

It's clearly a spotify problem, check your credentials

The-Spartan commented 10 months ago

It is a spotify issue, however the credentials are correct. I am using credentials that worked less than a week ago, remade the application in the dev platform, rotated the secret and even tried another spotify account dev app. All give the same issue.

It is clear that this is the cause of the issue:

``Traceback (most recent call last): File "C:\Users\Chris\AppData\Local\Programs\Python\Python310\lib\site-packages\spotipy\oauth2.py", line 588, in refresh_access_token response.raise_for_status() File "C:\Users\Chris\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\models.py", line 1021, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://accounts.spotify.com/api/token```

Trying on another device entirely (installing on laptop) it works fine with the same settings. What would be a culprit for it failing on the PC? i have tried fully uninstalling and reinstalling spotify_to_ytmusic etc on the PC to no avail.

Thanks for the app and your help

The-Spartan commented 10 months ago

Found a way to consistently reproduce the issue:

  1. Setup spotify_to_ytmusic with both option
  2. use the tool successfully
  3. setup again with different account credentials (different user to transfer over)
  4. fails (error above)

reinstalling spotipy, spotify_to_ytmusic etc does not work. Do you happen to know if there is some weird caching going on?

Thanks

bchangip commented 8 months ago

I ran into the same issue, looking at the code I did find some cache related code.

Fixed the issue by removing the ~/.cache/spotify_to_ytmusic directory and running the setup process again.

Hope that helps ✌️

TonyOuyangGit commented 8 months ago

Hi, this is a very tricky issue, according to the developer forum here: https://community.spotify.com/t5/Spotify-for-Developers/INVALID-CLIENT-Invalid-redirect-URI/td-p/5228936 to resolve the redirect URI issue, you'll need to add http://localhost in your sportify dashboard settings in Redirect URIs section, by default it's only https://open.spotify.com/, which does not apply to our case

@sigma67 I would suggest adding this in README

sigma67 commented 8 months ago

It's literally right there in the README

mfractal commented 4 months ago

can confirm this happens when trying to setup a second account. first account works fine but the second account throws this error even though the creds are correct. trying to locate the default cache location on macos to delete the file as @bchangip suggested above. @sigma67 mind having a second look ?

EDIT : confirmed the solution for mac is deleting

/System/Volumes/Data/Users/----YOUR-USERNAME-----/Library/Caches/spotify_to_ytmusic/spotipy.cache

sigma67 commented 4 months ago

@mfractal thanks for providing actual reproduction instructions