-
Notifications
You must be signed in to change notification settings - Fork 971
Description
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.02.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.