Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'str' object has no attribute 'get_cached_token' #430

Closed
ritiek opened this issue Jan 23, 2020 · 5 comments
Closed

AttributeError: 'str' object has no attribute 'get_cached_token' #430

ritiek opened this issue Jan 23, 2020 · 5 comments
Labels

Comments

@ritiek
Copy link
Collaborator

ritiek commented Jan 23, 2020

The recent merge of #428 (87a72a0) 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 87a72a0.

This needs to be checked.

@ritiek ritiek added the bug label Jan 23, 2020
@stephanebruckert
Copy link
Member

Sorry about this, I've temporarily reverted that PR 26db832 and will have a better look at it tonight

@ritiek
Copy link
Collaborator Author

ritiek commented 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!

@stephanebruckert
Copy link
Member

@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

@MaZderMind
Copy link
Contributor

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.

@stephanebruckert
Copy link
Member

@MaZderMind, @ritiek please let me know what you think of #263 (comment)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants