mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-04-26 16:15:51 +03:00
[GH-ISSUE #605] Spotify OAuth error : Couldn't read cache, Couldn't refresh token and Illegal URI #362
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#362
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 @nahar-senior on GitHub (Nov 8, 2020).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/605
I have a couple of things that are going wrong, and I have spent a considerable amount of time to fix it. I was first able to run the code below, Initially I did not pass the cache path as a parameter to the auth_manager. The code worked for an hour (since the token expires every hour), I then started running into errors regarding token refresh.
I then added the cache path as an added parameter and am getting two errors:
I have already checked the Redirect URI on my spotify developer dashboard and it matches what I have passed to the script.
Could I get a way to fix this as well as refresh the token if it's expired?
code
Output
Environment:
@Peter-Schorn commented on GitHub (Nov 8, 2020):
Do not create a new instance of
Spotifyeach time you callget_top_artist. You should create it in the initializer forUserDatainstead. Your script should only ever create a single instance ofSpotifyfor each Spotify user. The reason your are getting a "Couldn't read cache at <cache_path>" error may simply be because the first time you create an instance ofSpotifythe cache file does not exist. Have you checked whether it does exist? If the file does not exist and you are running the script for the first time (or the first time since you changed the cache path), then you can safely ignore this error.In order to provide more help I will need to see what your config file looks like. If you post it here, make sure to redact sensitive information, such as your client id and client secret.
@Peter-Schorn commented on GitHub (Nov 8, 2020):
@stephanebruckert Is there a reason why a warning is emitted when the cache file does not exist at the specified path? When the script is being run for the first time, it should be expected that the cache file does not exist yet, so this shouldn't be considered an error condition. This behavior has confused me in the past as well.
@stephanebruckert commented on GitHub (Nov 11, 2020):
@Peter-Schorn you are right it shouldn't show this warning if the file does not exist, only if it cannot be read (eg. no correct permission). We should change it, and possibly prepend all warnings with
Warning:so that people don't think it's an error to worry too much about@Peter-Schorn commented on GitHub (Nov 11, 2020):
@stephanebruckert I'll work on a PR to that effect.
@nahar-senior commented on GitHub (Nov 11, 2020):
Thank you, I will update as per your suggestion and share the output
@nahar-senior commented on GitHub (Nov 14, 2020):
Hi Peter,
I have made the changes that you suggested but I get the same error unfortunately. Here is my updated code:
Below is the config file:
When I ran this script, I already had an .cache file in my directory. But I still get the below error:
Here is the URL I'm directed to:
https://accounts.spotify.com/authorize?client_id=%<my_client_id>%27&response_type=code&redirect_uri=%27http%3A%2F%2Flocalhost%3A8888%2Fcallback%27&scope=user-top-read
@stephanebruckert commented on GitHub (Nov 14, 2020):
What is the exact name of the cache file? Is it
.cacheor is it.cache-21ranjgq5en4j53pcqfcedopi? It should be the later according to your codeThe PR by @Peter-Schorn was merged to master, please use that version so we get better warnings / error messages and let us know what is shows
I haven't tested your code yet, but I don't see anything that is too wrong. I just see you are still using the following the following:
while these are optional. It should work with it, but since some work was done around it lately, perhaps there is a bug. Can you please remove these 2 lines and try again?
@Peter-Schorn commented on GitHub (Nov 14, 2020):
@stephanebruckert @siddharthnahar The reason for the error is actually much simpler than you think. The config file should not have quotes around the values. If you print the values after you retrieve them from the file, you will see that the quotes are included as part of the values.
@Peter-Schorn commented on GitHub (Nov 14, 2020):
Take a look at one of the errors you received:
The logger does not enclose the file path in quotes; the quotes are part of the value, which is clearly not what you want.
Take a look at the documentation for configparser for how to properly format the config file.