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

auth_manager=SpotifyOAuth( causes indefinite hanging if provided with invalid client id or secret #957

Open
Lightningtow opened this issue Apr 4, 2023 · 2 comments
Labels

Comments

@Lightningtow
Copy link

Lightningtow commented Apr 4, 2023

Describe the bug
When there's no valid .cache file for Spotipy to draw from, and an invalid client ID or secret is provided to the authorization code flow, when you next use the sp object, the code opens a webpage that says INVALID_CLIENT: Invalid client and then hangs indefinitely. A try/except does nothing.

If provided with an invalid callback URI (regardless of the validity of the client ID and secret), it will throw an error when you enter the URL you were sent to, so you're able to try/except as normal.

Your code

print("authing")  # behaves the same if you use environment variables instead of hardcoding
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id='invalid id', 
                                   client_secret='invalid secret',
                                   redirect_uri='http://localhost:8080',  # this part is valid
                                   scope=SCOPES))   # this is also valid
print("after auth request")
sp.me()  # also tested with `sp.playlist_items()` and `sp.track`, they all behave the same
print("end authing")

Expected behavior
If provided with an invalid client ID and/or secret, it should throw an error, one that can be properly caught with a try/except.
Seems the error would be better placed on the sp = spotipy line of code, but would work fine if it instead threw when it got used next, in this case sp.me(). Doesn't really matter, as long as it gives an error that can be caught.

Output
Running the above code results in this:

authing
after auth request

and then indefinite hanging. The behavior is exactly the same even if you use try/except around both statements, or if only one ID/secret is invalid.

Environment:

  • OS: Windows
  • Python version: 3.9
  • Spotipy version 2.12.0 2.22.1 (typo)
  • IDE: Pycharm

Additional context
Not part of the bug report, but does anyone know an option besides A) bundle my app's client secret with the rest of my code and distribute it with cx_Freeze, which is no bueno lmao, or B) force my users to make their own app and provide their own IDs and secrets? I chose option B, which is why I'm making the above bug report rn, because I can't assume that my end user will provide valid IDs or secrets.

@Lightningtow Lightningtow changed the title Code hangs indefinitely if provided with invalid client id or secret auth_manager=SpotifyOAuth hangs indefinitely if provided with invalid client id or secret Apr 4, 2023
@Lightningtow Lightningtow changed the title auth_manager=SpotifyOAuth hangs indefinitely if provided with invalid client id or secret auth_manager=SpotifyOAuth( hangs indefinitely if provided with invalid client id or secret Apr 4, 2023
@Lightningtow Lightningtow changed the title auth_manager=SpotifyOAuth( hangs indefinitely if provided with invalid client id or secret auth_manager=SpotifyOAuth( causes indefinite hanging if provided with invalid client id or secret Apr 4, 2023
@stephanebruckert
Copy link
Member

Haven't tried it yet, but I see you are using quite an old version of spotipy, could you please upgrade and confirm the problem persists?

@Lightningtow
Copy link
Author

Haven't tried it yet, but I see you are using quite an old version of spotipy, could you please upgrade and confirm the problem persists?

That was a typo, sorry. I'm using 2.22.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants