[GH-ISSUE #503] Error 400 on revoked authentication #298

Open
opened 2026-02-27 23:21:52 +03:00 by kerem · 4 comments
Owner

Originally created by @IzHoBX on GitHub (May 28, 2020).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/503

Steps to reproduce:

  1. user revokes authentication on Spotify account page.
  2. Reruns authentication on the same user
  3. Encounter error message below.
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/spotipy/oauth2.py", line 464, in refresh_access_token
    response.raise_for_status()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/models.py", line 941, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://accounts.spotify.com/api/token

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/spotipy/util.py", line 88, in prompt_for_user_token
    token_info = sp_oauth.get_cached_token()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/spotipy/oauth2.py", line 263, in get_cached_token
    token_info["refresh_token"]
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/spotipy/oauth2.py", line 476, in refresh_access_token
    headers)
spotipy.exceptions.SpotifyException: http status: 400, code:-1 - Couldn't refresh token: code:400 reason:Bad Request

Reason: when oauth2.py attempts to refresh token, Spotify server returns error refresh_access_token() doesn't handle it.

Expected behaviour: show Spotify authentication page in browser to allow user re-authenticate

Suggestion: adds error handling around util.py prompt_for_user_token() line 88

Originally created by @IzHoBX on GitHub (May 28, 2020). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/503 Steps to reproduce: 1. user revokes authentication on Spotify account page. 2. Reruns authentication on the same user 3. Encounter error message below. ```Couldn't refresh token. Response Status Code: 400 Reason: Bad Request Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/spotipy/oauth2.py", line 464, in refresh_access_token response.raise_for_status() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/models.py", line 941, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://accounts.spotify.com/api/token During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/spotipy/util.py", line 88, in prompt_for_user_token token_info = sp_oauth.get_cached_token() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/spotipy/oauth2.py", line 263, in get_cached_token token_info["refresh_token"] File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/spotipy/oauth2.py", line 476, in refresh_access_token headers) spotipy.exceptions.SpotifyException: http status: 400, code:-1 - Couldn't refresh token: code:400 reason:Bad Request ``` Reason: when oauth2.py attempts to refresh token, Spotify server returns error refresh_access_token() doesn't handle it. Expected behaviour: show Spotify authentication page in browser to allow user re-authenticate Suggestion: adds error handling around util.py prompt_for_user_token() line 88
Author
Owner

@lucas-campbell commented on GitHub (Jun 15, 2020):

Bumping this, having the same problem. Also occurs when using another spotify app and attempting to run a login sequence with the new client id/ client secret (after I had previously revoked permission on the first app, I had set up a new one to try and get around this issue).

<!-- gh-comment-id:644379533 --> @lucas-campbell commented on GitHub (Jun 15, 2020): Bumping this, having the same problem. Also occurs when using another spotify app and attempting to run a login sequence with the new client id/ client secret (after I had previously revoked permission on the first app, I had set up a new one to try and get around this issue).
Author
Owner

@dpnem commented on GitHub (Sep 3, 2020):

Something similar is happening to me as well.

I built a Spotipy app that successfully ran. I then changed my Client Secret, attached the new Client Secret to the environment variable SPOTIPY_CLIENT_SECRET and receive the following error:

SpotifyException: http status: 400, code:-1 - Couldn't refresh token: code:400 reason:Bad Request

<!-- gh-comment-id:686398172 --> @dpnem commented on GitHub (Sep 3, 2020): Something similar is happening to me as well. I built a Spotipy app that successfully ran. I then changed my Client Secret, attached the new Client Secret to the environment variable SPOTIPY_CLIENT_SECRET and receive the following error: SpotifyException: http status: 400, code:-1 - Couldn't refresh token: code:400 reason:Bad Request
Author
Owner

@NicolasKermen commented on GitHub (Dec 25, 2020):

Hi,
I may have a work-around to fix this issue.
I'm developping a little script to import my m3u playlist file to different spotify account. It was perfectly working with the first account but when I wanted to import a playlist to a second spotify account, I got this error.
I noticed in the working directory a .cache-xxxx file which has been created during the first use of spotify.
I suppressed this file and it's works !

<!-- gh-comment-id:751258485 --> @NicolasKermen commented on GitHub (Dec 25, 2020): Hi, I may have a work-around to fix this issue. I'm developping a little script to import my m3u playlist file to different spotify account. It was perfectly working with the first account but when I wanted to import a playlist to a second spotify account, I got this error. I noticed in the working directory a **.cache-xxxx** file which has been created during the first use of spotify. I suppressed this file and it's works !
Author
Owner

@erit1566 commented on GitHub (Jan 2, 2021):

Similar to what Nicolas said, there is a .cache in the working directory and if you recycle that it prompts for login again.

<!-- gh-comment-id:753431192 --> @erit1566 commented on GitHub (Jan 2, 2021): Similar to what Nicolas said, there is a .cache in the working directory and if you recycle that it prompts for login again.
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#298
No description provided.