mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-04-27 00:25:54 +03:00
[GH-ISSUE #441] "You must either set a cache_path or a username" when using get_access_token #256
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#256
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 @CharleyPearce on GitHub (Feb 15, 2020).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/441
I am using the oauth for the login system to my app, however I'm not providing a cache path because I am using a different form of caching the token info on my server.
When a user is redirected back from Spotify, I use
sp_oauth.get_access_token(code)to verify the code. When this happens, I get the following error:This is because
get_access_tokencallsget_cached_token, which then throws an error when a cache path is not found.Is it possible that I can call
get_access_tokento verify a code from Spotify without needing a specified cache path?@stephanebruckert commented on GitHub (Feb 15, 2020):
How are you creating the
sp_oauthobject at first? To provide the username, you should be able to:either create
sp_oauthby doing something like:or by setting an environment variable
SPOTIPY_CLIENT_USERNAMEThen you won't need to pass a cache path anymore as it should be generated using your username
@CharleyPearce commented on GitHub (Feb 15, 2020):
I don't specify the username as when I define my sp_oauth object_object, I don't know the user's username at that point, so my definition will look something like this:
@stephanebruckert commented on GitHub (Feb 15, 2020):
Ha, I think I see. Currently the code is coupled with the fact that we want to cache the token as a file. The good news is we can work on changing that.
First, can I suggest something as a temporary workaround? Can you try to provide a random cache_path or username:
This will create a file that you will never use. It should allow you to retrieve the token using the code. Then I suppose you are storing this token somewhere else on your server, and the next time you want to use it, you could just do
sp = spotipy.Spotify(auth=token).Let me know how this goes. If this works for you, we might be able to remove this warning and make a version that allows working without cache, or better, with custom caches.
@stephanebruckert commented on GitHub (Feb 15, 2020):
Released in 2.9.0, thanks for the quick & simple PR!