[GH-ISSUE #321] Cache file default naming convention #181

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

Originally created by @zsiegel92 on GitHub (Sep 29, 2018).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/321

For some reason I'm unable to submit a pull request for this repository. I suggest changing line 49 of util.py from:

cache_path = cache_path or ".cache-" + username

to:

cache_path = cache_path or ".cache-" + username + "-" + str(scope)

Several issues have been opened regarding the need to interact with the browser more than once to refresh tokens when using util.py. I believe it is because the token cache file is overwritten when tokens of different scopes are created using the default token cache file naming in util.py. Of course, users of this library can manually enter a cache_path, but I believe other users ran into confusion, as I did. I don't believe the Spotipy documentation says enough about this function to justify making the default behavior of util.py nonfunctional for anyone creating multiple tokens.

Thank you for making this library. It is a useful tool for getting started interacting with the Spotify API quickly.

Originally created by @zsiegel92 on GitHub (Sep 29, 2018). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/321 For some reason I'm unable to submit a pull request for this repository. I suggest changing line 49 of `util.py` from: ```python cache_path = cache_path or ".cache-" + username ``` to: ```python cache_path = cache_path or ".cache-" + username + "-" + str(scope) ``` Several issues have been opened regarding the need to interact with the browser more than once to refresh tokens when using `util.py`. I believe it is because the token cache file is overwritten when tokens of different scopes are created using the default token cache file naming in `util.py`. Of course, users of this library can manually enter a `cache_path`, but I believe other users ran into confusion, as I did. I don't believe the Spotipy documentation says enough about this function to justify making the default behavior of `util.py` nonfunctional for anyone creating multiple tokens. Thank you for making this library. It is a useful tool for getting started interacting with the Spotify API quickly.
kerem 2026-02-27 23:21:15 +03:00
Author
Owner

@MxHex commented on GitHub (Jan 9, 2019):

I support that suggestion very much.
Also, you are not able to util.prompt_for_user_token() again after doing that once, because it will fail with
`Traceback (most recent call last):

token = util.prompt_for_user_token(username, scope)

/spotipy/util.py", line 56, in prompt_for_user_token

token_info = sp_oauth.get_cached_token()

/spotipy/oauth2.py", line 135, in get_cached_token

if 'scope' not in token_info or not self._is_scope_subset(self.scope, token_info['scope']):

/spotipy/oauth2.py", line 156, in _is_scope_subset

needle_scope = set(needle_scope.split())

AttributeError: 'NoneType' object has no attribute 'split'`

<!-- gh-comment-id:452891348 --> @MxHex commented on GitHub (Jan 9, 2019): I support that suggestion very much. Also, you are not able to `util.prompt_for_user_token()` again after doing that once, because it will fail with `Traceback (most recent call last): token = util.prompt_for_user_token(username, scope) /spotipy/util.py", line 56, in prompt_for_user_token token_info = sp_oauth.get_cached_token() /spotipy/oauth2.py", line 135, in get_cached_token if 'scope' not in token_info or not self._is_scope_subset(self.scope, token_info['scope']): /spotipy/oauth2.py", line 156, in _is_scope_subset needle_scope = set(needle_scope.split()) AttributeError: 'NoneType' object has no attribute 'split'`
Author
Owner

@sanchitcop19 commented on GitHub (Jul 14, 2019):

God bless you @zsiegel92

<!-- gh-comment-id:511164898 --> @sanchitcop19 commented on GitHub (Jul 14, 2019): God bless you @zsiegel92
Author
Owner

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

Closing because too many unanswered questions https://github.com/plamere/spotipy/pull/432#issuecomment-578504990

<!-- gh-comment-id:608025300 --> @stephanebruckert commented on GitHub (Apr 2, 2020): Closing because too many unanswered questions https://github.com/plamere/spotipy/pull/432#issuecomment-578504990
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#181
No description provided.