* Fixed a bug in the initializers for the auth managers that produced a spurious warning message if you provide a cache handler and you set a value for the "SPOTIPY_CLIENT_USERNAME" environment variable.
* fixed a bug in _get_auth_response_local_server which occurs if you provide a state parameter and click cancel in the authorization dialog
* Fallback on decoding the error response body into text if decoding into JSON fails.
* Fall back on decoding oauth errors into text if decoding into JSON fails.
* Fixed unused `http_error` name in exeception clause.
* Updated CHANGELOG
Co-authored-by: Stéphane Bruckert <stephane.bruckert@gmail.com>
* Added DjangoSessionCacheHandler
Added `DjangoSessionCacheHandler`, a cache handler that stores the token in the session framework provided by Django. Web apps using spotipy with Django can directly use this for cache handling.
* removed whitespaces
* Added `MemoryCacheHandler`, a cache handler that simply stores the token info in memory as an instance attribute of this class.
* Fixed a bug in `CacheFileHandler.__init__`: The documentation says that the username will be retrieved from the environment, but it wasn't.
* 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.
* 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.
* Removed duplicate word "multiple" from CHANGELOG
* * Fixed the bugs in `SpotifyOAuth.refresh_access_token` and `SpotifyPKCE.refresh_access_token` which raised the incorrect exception upon receiving an error response from the server. This addresses #645.
* Fixed a bug in `RequestHandler.do_GET` in which the non-existent `state` attribute of `SpotifyOauthError` is accessed. This bug occurs when the user clicks "cancel" in the permissions dialog that opens in the browser.
* Cleaned up the documentation for `SpotifyClientCredentials.__init__`, `SpotifyOAuth.__init__`, and `SpotifyPKCE.__init__`.
* Removed unneeded import
* Added the following endpoints:
`Spotify.current_user_saved_episodes` `Spotify.current_user_saved_episodes_add` `Spotify.current_user_saved_episodes_delete` `Spotify.current_user_saved_episodes_contains` `Spotify.available_markets`
Added tests for the above endpoints.
* updated CHANGELOG
* Fixed flake8 issue
Co-authored-by: Stéphane Bruckert <stephane.bruckert@gmail.com>
* 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.
* 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.
* Removed duplicate word "multiple" from CHANGELOG
* * Fixed the bugs in `SpotifyOAuth.refresh_access_token` and `SpotifyPKCE.refresh_access_token` which raised the incorrect exception upon receiving an error response from the server. This addresses #645.
* Fixed a bug in `RequestHandler.do_GET` in which the non-existent `state` attribute of `SpotifyOauthError` is accessed. This bug occurs when the user clicks "cancel" in the permissions dialog that opens in the browser.
* Cleaned up the documentation for `SpotifyClientCredentials.__init__`, `SpotifyOAuth.__init__`, and `SpotifyPKCE.__init__`.
* Removed unneeded import
Co-authored-by: Stéphane Bruckert <stephane.bruckert@gmail.com>
* Allow the scope to be either a list or comma separated string
* Move normalize scope to util file and make it a base method
Also adjust documentation to reflect the new scope parameter supporting a list
* Add change to CHANGELOG.md
* Refactor functions into static methods of AuthBase
Functions is_token_expired was a loose function that was added to
SpotifyClientCredentials, SpotifyPKCE, and SpotifyImplicitGrant classes
through a method on each class that passed the call to the loose
is_token_expired function. Function _is_scope_subset was duplicated on
SpotifyClientCredentials, SpotifyPKCE, and SpotifyImplicitGrant classes.
Refactoring is_token_expired and _is_scope_subset to be static methods
on SpotifyAuthBase means both are available for all derived classes and
require less boilerplate.
* Create CacheHandler to abstract caching tokens
Previous code only supported caching to and from json files in a given
directory. In addition, the get_cached_token method mixed getting and
getting the token in the same method.
This change creates a CacheHandler class to abstract out the caching
implementation and allow the user to cache tokens in any way they
see fit. For example, the user could create a MongoCache class to store
and retrieve tokens from a Mongo database and specify that
cache_handler=MongoCache in creating an auth_manager object.
To implement the CacheHandler abstraction, the following changes are
implemented:
The validation code in each get_cached_token method in SpotifyOAuth,
SpotifyPKCE, and SpotifyImplicitGrant is moved into a validate_token
method in each class.
The CacheHandler class is created with get_cached_token and
save_token_to_cache methods.
Previous instances of self.get_cached_token() are now replaced with
self.validate_token(self.cache_handler.get_cached_token()) to preserve
the getting and validation behaviour.
cache_handler is added as an argument to SpotifyOAuth, SpotifyPKCE, and
SpotifyImplicitGrant. Specifying a cache_handler now overrides any
specification of cache_path and/or username.
To preserve backwards compatibility in handling cache files, a
CacheFileHandler class extending CacheHandler is created. If no
cache_handler is specified, the cache_path and username arguments are
used to create an instance of CacheFileHandler. It may be worth
deprecating the cache_path and username fields in favour of using
CacheFileHandler.
Tests are also modified and extended to cover the new functionality. A
sample MemoryCache CacheHandler is created to test getting and saving to
a custom CacheHandler.
* Fix cache_handler subclass check for Python 2
* Split assert message to fix line over max length
* Split cache handlers into cache_handler.py
* flake8 and autopep fixes
* Fix init to allow importing CacheHandler
When spotipy is installed as a package, CacheHandler is not accessible
from a `from spotipy import CacheHandler` statement because the import
is not specified in the __init__.py file. This commit adds CacheHandler
and CacheFileHandler to the init file so the user can import them.
* flake8 fix
* Add cache_path & username deprecation warning
When cache_path or username are specified in the constructors of
SpotifyOAuth, SpotifyPKCE, or SpotifyImplicitGrant, the constructor
creates a CacheFileHandler instance under the hood. The user is
currently able to create a CacheFileHandler instance in two ways:
1. By creating it outside the SpotifyOAuth (or etc.) constructor and
passing it as the cache_handler
2. By passing cache_path and username to the constructor
Ideally, there would be one and only one obvious way to specify a
CacheFileHandler instance and the cache_handler approach allows any
CacheHandler to be used, so passing the cache_path or username to the
constructor should be deprecated.
* Update flask example to use CacheFileHandler
* Update changelog with deprecation warning info
* Restore token caching methods on auth_manager
Change 9550c8fd86 in
https://github.com/plamere/spotipy accidentally broke the caching
functionality in SpotifyOAUth, SpotifyPKCE, and SpotifyImplicitGrant by
removing the get_cached_token and _save_token_info methods from the
auth_manager object. Users with existing codebases that use the
get_cached_token and _save_token_info methods directly will experience
errors if they upgrade spotipy.
This commit restores the get_cached_token and _save_token_info methods
on the three auth_manager classes as aliases for the corresponding
methods in the cache_handler. Deprecation warnings are also added to
the get_cached_token and _save_token_info methods to direct users to
switch to using the new cache_handler approach.
* Add deprecation warning to docstrings
* Rearrange depr. warn for cache_path & username
Rearrange logic so that deprecation warning always triggers if
cache_path or username are specified. Previously, if cache_handler was
specified, no deprecation warning would be raised if cache_path or
username were specified.
In addition, if both cache_handler and cache_path or username are
specified, a new warning will be raised alongside the deprecation
warning to let the user know that the cache_path and username fields
will be ignored in favour of the cache_handler.
* Refactor functions into static methods of AuthBase
Functions is_token_expired was a loose function that was added to
SpotifyClientCredentials, SpotifyPKCE, and SpotifyImplicitGrant classes
through a method on each class that passed the call to the loose
is_token_expired function. Function _is_scope_subset was duplicated on
SpotifyClientCredentials, SpotifyPKCE, and SpotifyImplicitGrant classes.
Refactoring is_token_expired and _is_scope_subset to be static methods
on SpotifyAuthBase means both are available for all derived classes and
require less boilerplate.
* Create CacheHandler to abstract caching tokens
Previous code only supported caching to and from json files in a given
directory. In addition, the get_cached_token method mixed getting and
getting the token in the same method.
This change creates a CacheHandler class to abstract out the caching
implementation and allow the user to cache tokens in any way they
see fit. For example, the user could create a MongoCache class to store
and retrieve tokens from a Mongo database and specify that
cache_handler=MongoCache in creating an auth_manager object.
To implement the CacheHandler abstraction, the following changes are
implemented:
The validation code in each get_cached_token method in SpotifyOAuth,
SpotifyPKCE, and SpotifyImplicitGrant is moved into a validate_token
method in each class.
The CacheHandler class is created with get_cached_token and
save_token_to_cache methods.
Previous instances of self.get_cached_token() are now replaced with
self.validate_token(self.cache_handler.get_cached_token()) to preserve
the getting and validation behaviour.
cache_handler is added as an argument to SpotifyOAuth, SpotifyPKCE, and
SpotifyImplicitGrant. Specifying a cache_handler now overrides any
specification of cache_path and/or username.
To preserve backwards compatibility in handling cache files, a
CacheFileHandler class extending CacheHandler is created. If no
cache_handler is specified, the cache_path and username arguments are
used to create an instance of CacheFileHandler. It may be worth
deprecating the cache_path and username fields in favour of using
CacheFileHandler.
Tests are also modified and extended to cover the new functionality. A
sample MemoryCache CacheHandler is created to test getting and saving to
a custom CacheHandler.
* Fix cache_handler subclass check for Python 2
* Split assert message to fix line over max length
* Split cache handlers into cache_handler.py
* flake8 and autopep fixes
* Fix init to allow importing CacheHandler
When spotipy is installed as a package, CacheHandler is not accessible
from a `from spotipy import CacheHandler` statement because the import
is not specified in the __init__.py file. This commit adds CacheHandler
and CacheFileHandler to the init file so the user can import them.
* flake8 fix
* 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.
* 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.
* Removed duplicate word "multiple" from CHANGELOG
Co-authored-by: Stéphane Bruckert <stephane.bruckert@gmail.com>
* 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.
* Small adjustment on sing_out function
First, thanks for this. It has been a great help. I was having trouble with this function, getting a TypeError (TypeError: can only concatenate str (not "NoneType") to str) because apparently the second os.remove(session_cache_path()) is trying to delete a file that does not exist anymore so this is what worked for me.
* Change description on app.py file
* Update app.py on line 79
Fixed indent
* - Added scope, 'playlist-read-private', to examples that access user playlists using the spotipy api: current_user_playlists() (fixes#591)
* Fix example to use user_playlists again
Co-authored-by: Stephane Bruckert <stephane.bruckert@gmail.com>
* Fixplamere/spotipy#560
* Adhere to code style
* Update CHANGELOG.md for changes in 939f869bbc
* open_browser passed to get_auth_response should take precedence over the same argument in the constructor
* Update FAQ
* Add information about headless auth
* Add headless auth example
* Clean up namespace in SpotifyPKCE._get_auth_response_interactive
* Add Warning to SpotifyImplicitGrant.__init__
* Update changelog with addition of warning
* Improve SpotifyPKCE.get_authorization_url
Ensure that a code challenge has been generated for the auth url
* Clean up namespace in SpotifyPKCE._get_auth_response_interactive
* Duplicate parse_auth_response_url into SpotifyPKCE
* Update SpotifyPKCE security advisory
* Update changelog for PKCE refinements
* fixed uri issue in playlist_add_items
All uris were being converted to track uris
making it impossible to add episodes to playlists.
* Added tests for episode adds
also fixed creep uri so those tests no longer fail
* Fixed creep_url to match creep_uri
* revert pip version, added FIX to changelog
Co-authored-by: Paul Lamere <paull@spotify.com>
Some artist or track provide different translation for different language
usage. This requires send http request with Accept-Language in header.
Create this option for people who wants to see proper translation.
* Added base funtionality for PKCE Authorization - i538
* fixed a mistake with the auth code
* fixed more misunderstandings. fixed grant_access_token to now call authorization if needed
* added comments and references to code verifier and code challenge
* removed debug print statement
* updated unit tests for new PKCE flow
* cleaned up username issues - added doc strings to class
* fixed import issue, added user endpoint tests
* forgot to commit this file
* linted
* clarified comment
* no longer generates code verifier or challenge in constructor, only when needed
* fixed flake8 complaints, added forgotten unit tests
* fixed linting with unit tests
* anotha one
* added python3.5 support
* linting
* added to CHANGELOG
* removed as_dict option from get_access_token()
Co-authored-by: tomCLANCC <26153156+tomCLANCC@users.noreply.github.com>
* Update playlist endpoints to modern format
Deprecate user_playlist_* in favor of the following replacements:
* user_playlist_change_details -> playlist_change_details
* user_playlist_unfollow -> current_user_unfollow_playlist
* user_playlist_add_tracks -> playlist_add_tracks
* user_playlist_replace_tracks -> playlist_replace_tracks
* user_playlist_reorder_tracks -> playlist_reorder_tracks
* user_playlist_remove_all_occurrences_of_tracks -> playlist_remove_all_occurrences_of_tracks
* user_playlist_remove_specific_occurrences_of_tracks -> playlist_remove_specific_occurrences_of_tracks
* user_playlist_follow_playlist -> current_user_follow_playlist
* user_playlist_is_following -> playlist_is_following
* Add current_user_following_artists and current_user_following_users
* Update tests and examples
Resolve TODO in test_user_endpoints.py > SpotifyFollowApiTests.test_user_follows_and_unfollows_user
Use modern playlist endpoints (no username required) in tests and examples.
* Update changelog
* Deprecate playlist_tracks in favor of playlist_items
* Link deprecated functions to new functions and change tracks to items
* Fix references to playlist_tracks
* Change test_playlist_add_items as requested
* Allow for total headless mode by instructing the user to open the URL in a browser.
* Fix line too long
* Update changelog
* Clarify changelog entry
* Remove reduntant log about pasting the URL.