[GH-ISSUE #483] current_user_top_tracks throwing 403 #283

Closed
opened 2026-02-27 23:21:47 +03:00 by kerem · 8 comments
Owner

Originally created by @tizonia on GitHub (Apr 26, 2020).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/483

Hi,

I'm using spotipy-2.11.2 and spotify_token to authenticate like this:

token = spotify_token.start_session(user, password)[0]
spotipy.Spotify(auth=self.token)

Not sure if I'm doing something wrong here:

  • spotify.current_user_saved_tracks(limit=50, offset=0) works perfectly fine.
  • However, spotify.current_user_top_tracks(limit=50) is throwing an exception:
DEBUG:spotipy.client:Sending GET to https://api.spotify.com/v1/me/top/tracks with Headers: {'Authorization': 'Bearer <removed>', 'Content-Type': 'application/json'} and Body: None 
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.spotify.com:443
DEBUG:urllib3.connectionpool:https://api.spotify.com:443 "GET /v1/me/top/tracks?time_range=medium_term&limit=50&offset=0 HTTP/1.1" 403 0
ERROR:spotipy.client:HTTP Error for GET to https://api.spotify.com/v1/me/top/tracks returned 403 due to error
(SpotifyException) : http status: 403, code:-1 - https://api.spotify.com/v1/me/top/tracks?time_range=medium_term&limit=50&offset=0:
 error
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/spotipy/client.py", line 173, in _internal_call
    response.raise_for_status()
  File "/usr/local/lib/python3.6/dist-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://api.spotify.com/v1/me/top/tracks?time_range=medium_term&limit=50&offset=0

Thanks!

Originally created by @tizonia on GitHub (Apr 26, 2020). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/483 Hi, I'm using spotipy-2.11.2 and `spotify_token` to authenticate like this: ``` token = spotify_token.start_session(user, password)[0] spotipy.Spotify(auth=self.token) ``` Not sure if I'm doing something wrong here: - `spotify.current_user_saved_tracks(limit=50, offset=0)` works perfectly fine. - However, `spotify.current_user_top_tracks(limit=50)` is throwing an exception: ``` DEBUG:spotipy.client:Sending GET to https://api.spotify.com/v1/me/top/tracks with Headers: {'Authorization': 'Bearer <removed>', 'Content-Type': 'application/json'} and Body: None DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.spotify.com:443 DEBUG:urllib3.connectionpool:https://api.spotify.com:443 "GET /v1/me/top/tracks?time_range=medium_term&limit=50&offset=0 HTTP/1.1" 403 0 ERROR:spotipy.client:HTTP Error for GET to https://api.spotify.com/v1/me/top/tracks returned 403 due to error (SpotifyException) : http status: 403, code:-1 - https://api.spotify.com/v1/me/top/tracks?time_range=medium_term&limit=50&offset=0: error Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/spotipy/client.py", line 173, in _internal_call response.raise_for_status() File "/usr/local/lib/python3.6/dist-packages/requests/models.py", line 940, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://api.spotify.com/v1/me/top/tracks?time_range=medium_term&limit=50&offset=0 ``` Thanks!
kerem 2026-02-27 23:21:47 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@stephanebruckert commented on GitHub (Apr 26, 2020):

Hello,

spotify.current_user_top_tracks() works for me. It's doing a GET to https://api.spotify.com/v1/me/top/tracks?time_range=medium_term&limit=50&offset=0 and returns 50 tracks

Maybe it was a transient error?

<!-- gh-comment-id:619640098 --> @stephanebruckert commented on GitHub (Apr 26, 2020): Hello, `spotify.current_user_top_tracks()` works for me. It's doing a `GET` to `https://api.spotify.com/v1/me/top/tracks?time_range=medium_term&limit=50&offset=0` and returns 50 tracks Maybe it was a transient error?
Author
Owner

@tizonia commented on GitHub (Apr 26, 2020):

Still not working here...

<!-- gh-comment-id:619642087 --> @tizonia commented on GitHub (Apr 26, 2020): Still not working here...
Author
Owner

@tizonia commented on GitHub (Apr 26, 2020):

current_user_top_artists is throwing the same error:

EBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.spotify.com:443
DEBUG:urllib3.connectionpool:https://api.spotify.com:443 "GET /v1/me/top/artists?time_range=medium_term&limit=50&offset=0 HTTP/1.1" 403 0
ERROR:spotipy.client:HTTP Error for GET to https://api.spotify.com/v1/me/top/artists returned 403 due to error
[Spotify] (SpotifyException) : http status: 403, code:-1 - https://api.spotify.com/v1/me/top/artists?time_range=medium_term&limit=50&offset=0:
 error
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/spotipy/client.py", line 173, in _internal_call
    response.raise_for_status()
  File "/usr/local/lib/python3.6/dist-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://api.spotify.com/v1/me/top/artists?time_range=medium_t
<!-- gh-comment-id:619642893 --> @tizonia commented on GitHub (Apr 26, 2020): `current_user_top_artists` is throwing the same error: ``` EBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.spotify.com:443 DEBUG:urllib3.connectionpool:https://api.spotify.com:443 "GET /v1/me/top/artists?time_range=medium_term&limit=50&offset=0 HTTP/1.1" 403 0 ERROR:spotipy.client:HTTP Error for GET to https://api.spotify.com/v1/me/top/artists returned 403 due to error [Spotify] (SpotifyException) : http status: 403, code:-1 - https://api.spotify.com/v1/me/top/artists?time_range=medium_term&limit=50&offset=0: error Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/spotipy/client.py", line 173, in _internal_call response.raise_for_status() File "/usr/local/lib/python3.6/dist-packages/requests/models.py", line 940, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://api.spotify.com/v1/me/top/artists?time_range=medium_t ```
Author
Owner

@tizonia commented on GitHub (Apr 26, 2020):

current_user_recently_played is working OK

<!-- gh-comment-id:619643395 --> @tizonia commented on GitHub (Apr 26, 2020): `current_user_recently_played` is working OK
Author
Owner

@stephanebruckert commented on GitHub (Apr 27, 2020):

Is your token using the scope user-top-read ? https://developer.spotify.com/documentation/general/guides/scopes/

<!-- gh-comment-id:619650246 --> @stephanebruckert commented on GitHub (Apr 27, 2020): Is your token using the scope `user-top-read` ? https://developer.spotify.com/documentation/general/guides/scopes/
Author
Owner

@tizonia commented on GitHub (Apr 27, 2020):

@stephanebruckert

Thanks!, this was the problem. I was not setting the necessary scope. I'm still learning about the scopes and how to use them.

Is there a way to retrieve the daily mixes or the discover weekly playlist?

<!-- gh-comment-id:620240481 --> @tizonia commented on GitHub (Apr 27, 2020): @stephanebruckert Thanks!, this was the problem. I was not setting the necessary scope. I'm still learning about the scopes and how to use them. Is there a way to retrieve the daily mixes or the discover weekly playlist?
Author
Owner

@ritiek commented on GitHub (Apr 28, 2020):

Is there a way to retrieve the daily mixes or the discover weekly playlist?

Spotify does not provide a special way to access these playlists. You'll need to iterate on a user's available playlists yourself and check for a playlist with the name "Discover Weekly" (or ones with the daily mix names) owned by "Spotify" user.

You also might want to use the scope playlist-read-private since these playlists are private by default.

<!-- gh-comment-id:620320222 --> @ritiek commented on GitHub (Apr 28, 2020): > Is there a way to retrieve the daily mixes or the discover weekly playlist? Spotify does not provide a special way to access these playlists. You'll need to iterate on a user's available playlists yourself and check for a playlist with the name "Discover Weekly" (or ones with the daily mix names) owned by "Spotify" user. You also might want to use the scope `playlist-read-private` since these playlists are private by default.
Author
Owner

@tizonia commented on GitHub (Apr 29, 2020):

@stephanebruckert / @ritiek

Thanks, I've been able to access the daily mixes and the discover weekly using the read-private scope. But I noticed that I had to 'like' them to make them show up in the list returned by Spotify.

<!-- gh-comment-id:621072200 --> @tizonia commented on GitHub (Apr 29, 2020): @stephanebruckert / @ritiek Thanks, I've been able to access the daily mixes and the discover weekly using the read-private scope. But I noticed that I had to 'like' them to make them show up in the list returned by Spotify.
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#283
No description provided.