[GH-ISSUE #430] AttributeError: 'str' object has no attribute 'get_cached_token' #254

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

Originally created by @ritiek on GitHub (Jan 23, 2020).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/430

The recent merge of #428 (87a72a060f) seems to be breaking this example code:

import spotipy
import spotipy.oauth2 as oauth2

CLIENT_ID = 'client_id'
CLIENT_SECRET = 'client_secret'

credentials = oauth2.SpotifyClientCredentials(
        client_id=CLIENT_ID,
        client_secret=CLIENT_SECRET)

token = credentials.get_access_token()
spotify = spotipy.Spotify(auth=token)

playlist_url = "https://open.spotify.com/playlist/3Fm8szwHhMSQHQNxc4u22x"
playlist = spotify.playlist(playlist_url)

with this error:

Traceback (most recent call last):
  File "test.py", line 21, in <module>
    playlist = spotify.playlist(playlist_url)
  File "/home/ritiek/Downloads/spotipy/spotipy/client.py", line 393, in playlist
    return self._get("playlists/%s" % (plid), fields=fields, market=market)
  File "/home/ritiek/Downloads/spotipy/spotipy/client.py", line 166, in _get
    return self._internal_call('GET', url, payload, kwargs)
  File "/home/ritiek/Downloads/spotipy/spotipy/client.py", line 111, in _internal_call
    headers = self._auth_headers()
  File "/home/ritiek/Downloads/spotipy/spotipy/client.py", line 97, in _auth_headers
    token_info = self._auth.get_cached_token()
AttributeError: 'str' object has no attribute 'get_cached_token'

The code works OK for commits earlier than 87a72a060f.

This needs to be checked.

Originally created by @ritiek on GitHub (Jan 23, 2020). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/430 The recent merge of #428 (87a72a060fa82153f1995c9f9e563baf1aca3282) seems to be breaking this example code: ```python import spotipy import spotipy.oauth2 as oauth2 CLIENT_ID = 'client_id' CLIENT_SECRET = 'client_secret' credentials = oauth2.SpotifyClientCredentials( client_id=CLIENT_ID, client_secret=CLIENT_SECRET) token = credentials.get_access_token() spotify = spotipy.Spotify(auth=token) playlist_url = "https://open.spotify.com/playlist/3Fm8szwHhMSQHQNxc4u22x" playlist = spotify.playlist(playlist_url) ``` with this error: ```python Traceback (most recent call last): File "test.py", line 21, in <module> playlist = spotify.playlist(playlist_url) File "/home/ritiek/Downloads/spotipy/spotipy/client.py", line 393, in playlist return self._get("playlists/%s" % (plid), fields=fields, market=market) File "/home/ritiek/Downloads/spotipy/spotipy/client.py", line 166, in _get return self._internal_call('GET', url, payload, kwargs) File "/home/ritiek/Downloads/spotipy/spotipy/client.py", line 111, in _internal_call headers = self._auth_headers() File "/home/ritiek/Downloads/spotipy/spotipy/client.py", line 97, in _auth_headers token_info = self._auth.get_cached_token() AttributeError: 'str' object has no attribute 'get_cached_token' ``` The code works OK for commits earlier than 87a72a060fa82153f1995c9f9e563baf1aca3282. This needs to be checked.
kerem 2026-02-27 23:21:38 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@stephanebruckert commented on GitHub (Jan 23, 2020):

Sorry about this, I've temporarily reverted that PR github.com/plamere/spotipy@26db832e24 and will have a better look at it tonight

<!-- gh-comment-id:577612495 --> @stephanebruckert commented on GitHub (Jan 23, 2020): Sorry about this, I've temporarily reverted that PR https://github.com/plamere/spotipy/commit/26db832e24637f91411bb92bb031b41c54676e6d and will have a better look at it tonight
Author
Owner

@ritiek commented on GitHub (Jan 23, 2020):

Our test suite should've caught this one. I'll also take a look right now what went wrong in #428. Adding automated tests for this later should be a good idea too!

<!-- gh-comment-id:577695485 --> @ritiek commented on GitHub (Jan 23, 2020): Our test suite should've caught this one. I'll also take a look right now what went wrong in #428. Adding automated tests for this later should be a good idea too!
Author
Owner

@stephanebruckert commented on GitHub (Jan 23, 2020):

@ritiek I found what went wrong. Before merging, the tests were passing locally but I ran them from the /tests folder rather than the project folder, which would have used my pip-installed version of spotipy (2.7.1) instead of the project code. Will add a github action for tests as soon as this is fixed

<!-- gh-comment-id:577855830 --> @stephanebruckert commented on GitHub (Jan 23, 2020): @ritiek I found what went wrong. Before merging, the tests were passing locally but I ran them from the `/tests` folder rather than the project folder, which would have used my pip-installed version of spotipy (2.7.1) instead of the project code. Will add a github action for tests as soon as this is fixed
Author
Owner

@MaZderMind commented on GitHub (Jan 26, 2020):

A way to still allow this kind of api usage might be, to check the type of the auth= property and use it als-is when it is string.

<!-- gh-comment-id:578527761 --> @MaZderMind commented on GitHub (Jan 26, 2020): A way to still allow this kind of api usage might be, to check the type of the `auth=` property and use it als-is when it is string.
Author
Owner

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

@MaZderMind, @ritiek please let me know what you think of https://github.com/plamere/spotipy/issues/263#issuecomment-578539713

I'm closing the current issue since the breaking PR was reverted

<!-- gh-comment-id:578540970 --> @stephanebruckert commented on GitHub (Jan 26, 2020): @MaZderMind, @ritiek please let me know what you think of https://github.com/plamere/spotipy/issues/263#issuecomment-578539713 I'm closing the current issue since the breaking PR was reverted
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#254
No description provided.