[GH-ISSUE #1002] AttributeError: 'dict' object has no attribute 'get_access_token' #597

Closed
opened 2026-02-27 23:23:33 +03:00 by kerem · 2 comments
Owner

Originally created by @Zhiming77 on GitHub (Jul 12, 2023).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1002

I apologize, in advance, if this issue is inherently noob-ish. However, after solving my issue(s) relevant to the EOFError issue described here: https://github.com/spotipy-dev/spotipy/issues/632.

My bot is "successfully" hosted on Heroku, and I can use commands that don't access the Spotify API.
However, now when I try to access the API in any manner, for example, playlists = sp.current_user_playlists(), I am getting the following error:

[web.1]: File "/app/.heroku/python/lib/python3.11/site-packages/spotipy/client.py", line 338, in _put
[web.1]: return self._internal_call("PUT", url, payload, kwargs)
[web.1]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[web.1]: File "/app/.heroku/python/lib/python3.11/site-packages/spotipy/client.py", line 247, in _internal_call
[web.1]: headers = self._auth_headers()
[web.1]: ^^^^^^^^^^^^^^^^^^^^
[web.1]: File "/app/.heroku/python/lib/python3.11/site-packages/spotipy/client.py", line 238, in _auth_headers
[web.1]: token = self.auth_manager.get_access_token(as_dict=False)
[web.1]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[web.1]: AttributeError: 'dict' object has no attribute 'get_access_token'

The code I used to solve the issue described in the above link is as follows (and uses the MemoryCacheHandler):

sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri, scope=scope, show_dialog=False, open_browser=False, cache_handler=MemoryCacheHandler(token_info=token_info) ).get_access_token(as_dict=True, check_cache=True))

Why is self.auth_manager appearing as a dictionary herein (it would seem based on the spotipy code that it should not be appearing as a dictionary)?

Thank you in advance for any and all assistance!

Originally created by @Zhiming77 on GitHub (Jul 12, 2023). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1002 I apologize, in advance, if this issue is inherently noob-ish. However, after solving my issue(s) relevant to the EOFError issue described here: [https://github.com/spotipy-dev/spotipy/issues/632](url). My bot is "successfully" hosted on Heroku, and I can use commands that don't access the Spotify API. However, now when I try to access the API in any manner, for example, `playlists = sp.current_user_playlists()`, I am getting the following error: [web.1]: File "/app/.heroku/python/lib/python3.11/site-packages/spotipy/client.py", line 338, in _put [web.1]: return self._internal_call("PUT", url, payload, kwargs) [web.1]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [web.1]: File "/app/.heroku/python/lib/python3.11/site-packages/spotipy/client.py", line 247, in _internal_call [web.1]: headers = self._auth_headers() [web.1]: ^^^^^^^^^^^^^^^^^^^^ [web.1]: File "/app/.heroku/python/lib/python3.11/site-packages/spotipy/client.py", line 238, in _auth_headers [web.1]: token = self.auth_manager.get_access_token(as_dict=False) [web.1]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [web.1]: AttributeError: 'dict' object has no attribute 'get_access_token' The code I used to solve the issue described in the above link is as follows (and uses the MemoryCacheHandler): `sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri, scope=scope, show_dialog=False, open_browser=False, cache_handler=MemoryCacheHandler(token_info=token_info) ).get_access_token(as_dict=True, check_cache=True))` Why is self.auth_manager appearing as a dictionary herein (it would seem based on the spotipy code that it should not be appearing as a dictionary)? Thank you in advance for any and all assistance!
kerem 2026-02-27 23:23:33 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@jeffp123 commented on GitHub (Jul 14, 2023):

I think the error is because you are passing SpotifyOAuth(...).get_access_token(...) as the auth_manager param.

Try this instead? (reformatted for clarity and removed the .get_access_token(as_dict=True, check_cache=True))

sp = spotipy.Spotify(
  auth_manager=SpotifyOAuth(
    client_id=client_id,
    client_secret=client_secret,
    redirect_uri=redirect_uri,
    scope=scope,
    show_dialog=False,
    open_browser=False,
    cache_handler=MemoryCacheHandler(token_info=token_info),
  )
)
<!-- gh-comment-id:1636058009 --> @jeffp123 commented on GitHub (Jul 14, 2023): I think the error is because you are passing `SpotifyOAuth(...).get_access_token(...)` as the `auth_manager` param. Try this instead? (reformatted for clarity and removed the `.get_access_token(as_dict=True, check_cache=True)`) ``` sp = spotipy.Spotify( auth_manager=SpotifyOAuth( client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri, scope=scope, show_dialog=False, open_browser=False, cache_handler=MemoryCacheHandler(token_info=token_info), ) ) ```
Author
Owner

@stephanebruckert commented on GitHub (Jul 9, 2024):

Looks like a solution was provided, closing

<!-- gh-comment-id:2218362232 --> @stephanebruckert commented on GitHub (Jul 9, 2024): Looks like a solution was provided, closing
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#597
No description provided.