[GH-ISSUE #677] Spotify occasionally forces me to change my password, which affects all stored spotify tokens. Resetting password and creating new tokens, scripts don't work anymore #401

Closed
opened 2026-02-27 23:22:25 +03:00 by kerem · 7 comments
Owner

Originally created by @shillshocked on GitHub (Apr 20, 2021).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/677

Describe the bug
My Spotify password occasionally doesn't work anymore, which requires a password reset. Doing so invalidates all my old app tokens. I can regenerate those ones (I keep them as local files cached to refresh), but now they aren't working, even with no error message.

Originally created by @shillshocked on GitHub (Apr 20, 2021). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/677 **Describe the bug** My Spotify password occasionally doesn't work anymore, which requires a password reset. Doing so invalidates all my old app tokens. I can regenerate those ones (I keep them as local files cached to refresh), but now they aren't working, even with no error message.
kerem 2026-02-27 23:22:25 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@shillshocked commented on GitHub (Apr 20, 2021):

I'm guessing it might possibly have something to do with the new CacheFileHandler(), I haven't used this before and I'm unaware of the syntax.

<!-- gh-comment-id:822977844 --> @shillshocked commented on GitHub (Apr 20, 2021): I'm guessing it might possibly have something to do with the new CacheFileHandler(), I haven't used this before and I'm unaware of the syntax.
Author
Owner

@Peter-Schorn commented on GitHub (Apr 20, 2021):

It has nothing to do with the CacheFileHandler (what makes you think that?). This class contains the same caching logic as before. What error do you get when you try to make a request with the invalid token? And why do you have to change your Spotify password? I've never had to change my password.

<!-- gh-comment-id:822986645 --> @Peter-Schorn commented on GitHub (Apr 20, 2021): It has nothing to do with the `CacheFileHandler ` (what makes you think that?). This class contains the same caching logic as before. What error do you get when you try to make a request with the invalid token? And why do you have to change your Spotify password? I've never had to change my password.
Author
Owner

@shillshocked commented on GitHub (Apr 20, 2021):

I was reading the changelog and it looks as if the old way of doing things has been deprecated.

Deprecate specifing cache_path or username directly to SpotifyOAuth, SpotifyPKCE, and SpotifyImplicitGrant constructors, instead directing users to use the CacheFileHandler cache handler

Yeah, I don't know, I get that issue once in a while (maybe months, could be more frequently).

Anyways, I messed around a bit more with the code, and I managed to get the scripts running again.

Just curious, can you give me an example of how to use CacheFileHandler in a code snippet? Because I am still using the username authorization.

<!-- gh-comment-id:822990374 --> @shillshocked commented on GitHub (Apr 20, 2021): I was reading the changelog and it looks as if the old way of doing things has been deprecated. ` Deprecate specifing cache_path or username directly to SpotifyOAuth, SpotifyPKCE, and SpotifyImplicitGrant constructors, instead directing users to use the CacheFileHandler cache handler` Yeah, I don't know, I get that issue once in a while (maybe months, could be more frequently). Anyways, I messed around a bit more with the code, and I managed to get the scripts running again. Just curious, can you give me an example of how to use CacheFileHandler in a code snippet? Because I am still using the username authorization.
Author
Owner

@Peter-Schorn commented on GitHub (Apr 20, 2021):

from spotipy import Spotify, SpotifyOAuth, CacheFileHandler

spotify = Spotify(
    auth_manager=SpotifyOAuth(
        client_id=client_id,
        client_secret=client_secret,
        redirect_uri=redirect_uri,
        scope=scope_string,
        cache_handler=CacheFileHandler(username=username)
    )
)

Some of these parameters can be set in the environment variables. See the documentation comments for more information.
You may get an extraneous warning message as described in #674. Ignore it.

<!-- gh-comment-id:823003213 --> @Peter-Schorn commented on GitHub (Apr 20, 2021): ```python from spotipy import Spotify, SpotifyOAuth, CacheFileHandler spotify = Spotify( auth_manager=SpotifyOAuth( client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri, scope=scope_string, cache_handler=CacheFileHandler(username=username) ) ) ``` Some of these parameters can be set in the environment variables. See the documentation comments for more information. You may get an extraneous warning message as described in #674. Ignore it.
Author
Owner

@Peter-Schorn commented on GitHub (Apr 20, 2021):

What error message are you getting when you try to use an invalid token? I'm curious. Do you get a message saying "Refresh token revoked"?

<!-- gh-comment-id:823004011 --> @Peter-Schorn commented on GitHub (Apr 20, 2021): What error message are you getting when you try to use an invalid token? I'm curious. Do you get a message saying "Refresh token revoked"?
Author
Owner

@shillshocked commented on GitHub (Apr 20, 2021):

Thanks. Initially the problem was: spotipy "Couldn't refresh token: code:400," but that was just one of the errors.

I deleted the cached token. Made a new app. Put the new variables in to the .bashrc (and any reference in the python code, if applicable). That seemed to get things working. I had a few other issues but that was my own due to a recent update I made.

Sometimes you have to reset your client secret or make a new app to get things working again if your account is bugged. I think this happens every time you reset your password or if your account has been having login issues (perhaps a security feature of Spotify).

If the issue continues more often, I might make an automated way to speed up the reset/redeployment for future occurrences.

<!-- gh-comment-id:823005385 --> @shillshocked commented on GitHub (Apr 20, 2021): Thanks. Initially the problem was: spotipy "Couldn't refresh token: code:400," but that was just one of the errors. I deleted the cached token. Made a new app. Put the new variables in to the .bashrc (and any reference in the python code, if applicable). That seemed to get things working. I had a few other issues but that was my own due to a recent update I made. Sometimes you have to reset your client secret or make a new app to get things working again if your account is bugged. I think this happens every time you reset your password or if your account has been having login issues (perhaps a security feature of Spotify). If the issue continues more often, I might make an automated way to speed up the reset/redeployment for future occurrences.
Author
Owner

@Peter-Schorn commented on GitHub (Apr 20, 2021):

If you get a "Couldn't refresh token: code:400," error, then you should only need to delete the cached token info. You shouldn't need to create a new developer application. Try only deleting the cached token info next time.

<!-- gh-comment-id:823015409 --> @Peter-Schorn commented on GitHub (Apr 20, 2021): If you get a "Couldn't refresh token: code:400," error, then you should only need to delete the cached token info. You shouldn't need to create a new developer application. Try only deleting the cached token info next time.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#401
No description provided.