mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-06-19 09:13:53 +00:00
Suppress warnings when cache path does not exist. (#608)
* 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`. * 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. * Updated CHANGELOG.md * Removed `FileNotFoundError` because it does not exist in python 2.7 (*sigh*) and replaced it with a call to `os.path.exists`. * Replaced ` os.path.exists` with `error.errno == errno.ENOENT` to supress errors when the cache file does not exist.
This commit is contained in:
parent
3f2592d631
commit
d920f77713
@ -9,7 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- moved os.remove(session_cache_path()) inside try block to avoid TypeError on app.py example file
|
- moved os.remove(session_cache_path()) inside try block to avoid TypeError on app.py example file
|
||||||
|
- A warning will no longer be emitted when the cache file does not exist at the specified path
|
||||||
|
- The docs for the `auth` parameter of `Spotify.init` use the term "access token" instead of "authorization token"
|
||||||
|
|
||||||
## [2.16.1] - 2020-10-24
|
## [2.16.1] - 2020-10-24
|
||||||
|
|
||||||
|
|||||||
@ -114,7 +114,7 @@ class Spotify(object):
|
|||||||
"""
|
"""
|
||||||
Creates a Spotify API client.
|
Creates a Spotify API client.
|
||||||
|
|
||||||
:param auth: An authorization token (optional)
|
:param auth: An access token (optional)
|
||||||
:param requests_session:
|
:param requests_session:
|
||||||
A Requests session object or a truthy value to create one.
|
A Requests session object or a truthy value to create one.
|
||||||
A falsy value disables sessions.
|
A falsy value disables sessions.
|
||||||
|
|||||||
@ -11,6 +11,7 @@ __all__ = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
|
import errno
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@ -305,8 +306,10 @@ class SpotifyOAuth(SpotifyAuthBase):
|
|||||||
token_info = self.refresh_access_token(
|
token_info = self.refresh_access_token(
|
||||||
token_info["refresh_token"]
|
token_info["refresh_token"]
|
||||||
)
|
)
|
||||||
|
except IOError as error:
|
||||||
except IOError:
|
if error.errno == errno.ENOENT:
|
||||||
|
logger.debug("cache does not exist at: %s", self.cache_path)
|
||||||
|
else:
|
||||||
logger.warning("Couldn't read cache at: %s", self.cache_path)
|
logger.warning("Couldn't read cache at: %s", self.cache_path)
|
||||||
|
|
||||||
return token_info
|
return token_info
|
||||||
@ -784,8 +787,10 @@ class SpotifyPKCE(SpotifyAuthBase):
|
|||||||
token_info = self.refresh_access_token(
|
token_info = self.refresh_access_token(
|
||||||
token_info["refresh_token"]
|
token_info["refresh_token"]
|
||||||
)
|
)
|
||||||
|
except IOError as error:
|
||||||
except IOError:
|
if error.errno == errno.ENOENT:
|
||||||
|
logger.debug("cache does not exist at: %s", self.cache_path)
|
||||||
|
else:
|
||||||
logger.warning("Couldn't read cache at: %s", self.cache_path)
|
logger.warning("Couldn't read cache at: %s", self.cache_path)
|
||||||
|
|
||||||
return token_info
|
return token_info
|
||||||
@ -1029,8 +1034,10 @@ class SpotifyImplicitGrant(SpotifyAuthBase):
|
|||||||
|
|
||||||
if self.is_token_expired(token_info):
|
if self.is_token_expired(token_info):
|
||||||
return None
|
return None
|
||||||
|
except IOError as error:
|
||||||
except IOError:
|
if error.errno == errno.ENOENT:
|
||||||
|
logger.debug("cache does not exist at: %s", self.cache_path)
|
||||||
|
else:
|
||||||
logger.warning("Couldn't read cache at: %s", self.cache_path)
|
logger.warning("Couldn't read cache at: %s", self.cache_path)
|
||||||
|
|
||||||
return token_info
|
return token_info
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user