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

re-running setup for second account fails #85

Open
The-Spartan opened this issue Jan 5, 2024 · 8 comments
Open

re-running setup for second account fails #85

The-Spartan opened this issue Jan 5, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@The-Spartan
Copy link

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
Copy link
Owner

sigma67 commented Jan 5, 2024

It's clearly a spotify problem, check your credentials

@The-Spartan
Copy link
Author

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
Copy link
Author

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

@sigma67 sigma67 added the bug Something isn't working label Jan 22, 2024
@bchangip
Copy link

bchangip commented Mar 5, 2024

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
Copy link

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
Copy link
Owner

sigma67 commented Mar 7, 2024

It's literally right there in the README

@sigma67 sigma67 closed this as not planned Won't fix, can't repro, duplicate, stale Mar 7, 2024
@mfractal
Copy link

mfractal commented Jul 15, 2024

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 sigma67 changed the title Invalid client re-running setup for second account fails Jul 15, 2024
@sigma67
Copy link
Owner

sigma67 commented Jul 15, 2024

@mfractal thanks for providing actual reproduction instructions

@sigma67 sigma67 reopened this Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants