mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-04-27 00:25:54 +03:00
[GH-ISSUE #533] SpotifyOAuth Object not prompting user authorization (version 2.13.0) #321
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#321
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 @a-camarillo on GitHub (Jul 7, 2020).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/533
I'm currently trying to run the example for the Authorization Code Flow from the docs:
I can create the Spotify API client object but
SpotifyOAuthnever prompts user access.When I go to run
results = sp.current_user_saved_tracks()I get the error:spotipy.oauth2.SpotifyOauthError: You must either set a cache_path or a username.I'm not sure if the issue is with the Authorization Code Flow or something on my end.
@a-camarillo commented on GitHub (Jul 8, 2020):
I was able to prompt user authorization by calling
get_access_tokenand specifying a cache_path although I'm not entirely sure how this is processing since the path is to an empty text file which doesn't update with the token information.Still, I am curious as to why I can't replicate the code from the docs example. I will paste the code which worked for me below in hopes it will help.
@stephanebruckert commented on GitHub (Jul 12, 2020):
I agree that doesn't seem to behave correctly. I see at least two things that we need to fix:
You must either set a cache_path or a username.should be either removed or worse case be a warningSpotifyOAuthis currently not completing the authentication. It just "sets" all the parameters needed and waits for an endpoint to be called. You are right, it should prompt user access immediately@a-camarillo commented on GitHub (Jul 24, 2020):
It looks like the SpotifyOAuth class initializes both cache_path and username, but username also looks for an environment variable "client_username". Not entirely sure if this is what is causing the error to be raised
@vikivanov commented on GitHub (Jul 27, 2020):
I recently stumbled into the same issue and this worked for me but there is definitely something going wrong with SpotifyOAuth.
@DJSdev commented on GitHub (Aug 28, 2020):
The exception is being thrown from here. The reason is because
sp.current_user_top_tracks()is callingget_access_token()under the hood, which checks for a cached token first at the cache-path or in a file named.cache-<username>. When this fails due to no username/cache-path, it raises an exception and never reaches theself.get_authorization_code()function (a few lines later) to actually prompt a user to authorize access.The only reason I can see having need to specify a username is to differentiate cache files in multi-user environments.
@stephanebruckert
.cacheand if developers anticipate a multi-user environment, they can specify a username/cache-path as they can now.get_access_token()when SpotifyOAuth, SpotifyPKCE, or SpotifyImplicitGrant is inited so it can perform the authorize user steps, retrieved a cached token, or refresh a cached token. Any subsequent calls by the Spotify client would then use the cached token.@stephanebruckert commented on GitHub (Aug 29, 2020):
@DJSdev totally agree, let's do 1 & 2!
@stephanebruckert commented on GitHub (Aug 30, 2020):
@DJSdev I've implemented point 1 if you want to have a look https://github.com/plamere/spotipy/pull/567