mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-04-26 16:15:51 +03:00
[GH-ISSUE #957] auth_manager=SpotifyOAuth( causes indefinite hanging if provided with invalid client id or secret #577
Labels
No labels
api-bug
bug
dependencies
documentation
duplicate
enhancement
external-ide
headless-mode
implicit-grant-flow
invalid
missing-endpoint
pr-welcome
private-api
pull-request
question
spotipy3
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/spotipy#577
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Lightningtow on GitHub (Apr 4, 2023).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/957
Describe the bug
When there's no valid
.cachefile for Spotipy to draw from, and an invalid client ID or secret is provided to the authorization code flow, when you next use thespobject, the code opens a webpage that saysINVALID_CLIENT: Invalid clientand then hangs indefinitely. Atry/exceptdoes 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/exceptas normal.Your code
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 = spotipyline of code, but would work fine if it instead threw when it got used next, in this casesp.me(). Doesn't really matter, as long as it gives an error that can be caught.Output
Running the above code results in this:
and then indefinite hanging. The behavior is exactly the same even if you use
try/exceptaround both statements, or if only one ID/secret is invalid.Environment:
2.12.02.22.1 (typo)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.
@stephanebruckert commented on GitHub (Apr 8, 2023):
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 commented on GitHub (Apr 8, 2023):
That was a typo, sorry. I'm using 2.22.1
@AtomikkuLabs commented on GitHub (Apr 24, 2025):
Bump. I am also experiencing this. I would like to be able to handle it as it causes my program to hang and I cannot find a way to handle it as spotipy provides no exceptions, just hangs.
@stephanebruckert commented on GitHub (Apr 24, 2025):
@dieser-niko do you know if this is the same as https://github.com/spotipy-dev/spotipy/blob/master/FAQ.md#my-application-is-not-responding ? and if the warning from https://github.com/spotipy-dev/spotipy/pull/1134 should be displayed in this case?
@BigAtomikku you could try the suggestion from the FAQ to raise an error rather than indefinitely retrying, which hopefully will also give us more info.
@AtomikkuLabs commented on GitHub (Apr 24, 2025):
I tried an invalid client_id with:
and still no luck. It never reached print("3") or provided an error. Just sits there
@dieser-niko commented on GitHub (Apr 24, 2025):
I guess that spotipy is waiting for a never incoming request from the browser. It just prepares the URL for the browser and that's it. There's no check if the URL is valid or not. At least that's what I'm seeing without looking at the code.
@dieser-niko commented on GitHub (Apr 24, 2025):
The thing is, we won't know if it throws an error on the website because it doesn't redirect the user to the redirect_uri. There also doesn't seem to be a universal way to verify the client credentials.
What we/the user could do would be to use
SpotifyClientCredentialsbefore anything to make sure the credentials are correct.As for spotipy, I think we could make sure that the http server can be cancelled with Ctrl + C or similar.
Alternatively we could use
flaskorbottlesince they can handle a KeyboardInterrupt.@AtomikkuLabs commented on GitHub (May 26, 2025):
I created a pull request where I have fixed the issue for my use case at least.