[PR #655] [MERGED] Added cache handler to SpotifyClientCredentials and fixed a bug in refresh tokens methods that raised the wrong exception #982

Closed
opened 2026-02-28 00:03:06 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/spotipy-dev/spotipy/pull/655
Author: @Peter-Schorn
Created: 3/12/2021
Status: Merged
Merged: 3/13/2021
Merged by: @stephanebruckert

Base: masterHead: master


📝 Commits (10+)

  • 6faf49c Added an exception clause that catches FileNotFoundError and logs a debug message in SpotifyOAuth.get_cached_token, SpotifyPKCE.get_cached_token and SpotifyImplicitGrant.get_cached_token.
  • 8ae2cdd Changed docs for auth parameter of Spotify.init to access token instead of authorization token. In issue #599, a user confused the access token with the authorization code.
  • 957a26a Updated CHANGELOG.md
  • 04b2b02 Removed FileNotFoundError because it does not exist in python 2.7 (sigh) and replaced it with a call to os.path.exists.
  • 77a16dc Replaced os.path.exists with error.errno == errno.ENOENT to supress errors when the cache file does not exist.
  • caaabd5 Merge branch 'master' into master
  • 1e6107e Changed docs for search to mention that you can provide multiple multiple types to search for. The query parameters of requests are now logged. Added log messages for when the access token and refresh tokens are retrieved and when they are refreshed. Other small grammar fixes.
  • 5493ec6 Removed duplicate word "multiple" from CHANGELOG
  • 808946e Merge branch 'master' into master
  • bc29688 Merge branch 'master' into master

📊 Changes

2 files changed (+86 additions, -58 deletions)

View changed files

📝 CHANGELOG.md (+13 -1)
📝 spotipy/oauth2.py (+73 -57)

📄 Description

I see no reason why we shouldn't save the token info for the Client Credentials flow to persistent storage as well.

The methods for refreshing the access token now raise the proper exception . For example, instead of

spotipy.exceptions.SpotifyException: http status: 400, code:-1 - Couldn't refresh token: code:400 reason:Bad Request, reason: {'Authorization': 'Basic ZDEz...ZDc='}

you get

spotipy.oauth2.SpotifyOauthError: error: invalid_grant, error_description: Refresh token revoked

See #645


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/spotipy-dev/spotipy/pull/655 **Author:** [@Peter-Schorn](https://github.com/Peter-Schorn) **Created:** 3/12/2021 **Status:** ✅ Merged **Merged:** 3/13/2021 **Merged by:** [@stephanebruckert](https://github.com/stephanebruckert) **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (10+) - [`6faf49c`](https://github.com/spotipy-dev/spotipy/commit/6faf49cbe3cc417cec6671308c184c0542ecc0c5) Added an exception clause that catches `FileNotFoundError` and logs a debug message in `SpotifyOAuth.get_cached_token`, `SpotifyPKCE.get_cached_token` and `SpotifyImplicitGrant.get_cached_token`. - [`8ae2cdd`](https://github.com/spotipy-dev/spotipy/commit/8ae2cddcff67262b18ff770218f59b3341919dc4) Changed docs for `auth` parameter of `Spotify.init` to `access token` instead of `authorization token`. In issue #599, a user confused the access token with the authorization code. - [`957a26a`](https://github.com/spotipy-dev/spotipy/commit/957a26af2b6fd831db9317768e8d41154d518ccc) Updated CHANGELOG.md - [`04b2b02`](https://github.com/spotipy-dev/spotipy/commit/04b2b02beebdecc8d29b44547cd749d41d8a7789) Removed `FileNotFoundError` because it does not exist in python 2.7 (*sigh*) and replaced it with a call to `os.path.exists`. - [`77a16dc`](https://github.com/spotipy-dev/spotipy/commit/77a16dcd110008a904e78fa326408b86671ddf91) Replaced ` os.path.exists` with `error.errno == errno.ENOENT` to supress errors when the cache file does not exist. - [`caaabd5`](https://github.com/spotipy-dev/spotipy/commit/caaabd5a96c721201307b65b462cba461fe0e434) Merge branch 'master' into master - [`1e6107e`](https://github.com/spotipy-dev/spotipy/commit/1e6107e8b6098b8d84518e615deb5e95720155cb) Changed docs for `search` to mention that you can provide multiple multiple types to search for. The query parameters of requests are now logged. Added log messages for when the access token and refresh tokens are retrieved and when they are refreshed. Other small grammar fixes. - [`5493ec6`](https://github.com/spotipy-dev/spotipy/commit/5493ec68145a332f8fbe4a7aa245ebc806ba92ae) Removed duplicate word "multiple" from CHANGELOG - [`808946e`](https://github.com/spotipy-dev/spotipy/commit/808946e30290fa13463a63db9f111720f422f703) Merge branch 'master' into master - [`bc29688`](https://github.com/spotipy-dev/spotipy/commit/bc2968823d66fe0df41323a60effcac6e0e11bb9) Merge branch 'master' into master ### 📊 Changes **2 files changed** (+86 additions, -58 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+13 -1) 📝 `spotipy/oauth2.py` (+73 -57) </details> ### 📄 Description I see no reason why we shouldn't save the token info for the Client Credentials flow to persistent storage as well. The methods for refreshing the access token now raise the proper exception . For example, instead of ``` spotipy.exceptions.SpotifyException: http status: 400, code:-1 - Couldn't refresh token: code:400 reason:Bad Request, reason: {'Authorization': 'Basic ZDEz...ZDc='} ``` you get ``` spotipy.oauth2.SpotifyOauthError: error: invalid_grant, error_description: Refresh token revoked ``` See #645 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-28 00:03:06 +03:00
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#982
No description provided.