spotipy: Error when authenticating with credentials in code
I get an error when authenticating with credentials in code, as opposed to env variables. The client works when using env variables.
from config import APP_CLIENT_ID, APP_CLIENT_SECRET
auth_manager = SpotifyClientCredentials( client_id = APP_CLIENT_SECRET, client_secret = APP_CLIENT_SECRET )
sp = spotipy.Spotify( auth_manager = auth_manager )
…
C:\usr\Miniconda3\lib\site-packages\spotipy\oauth2.py in _request_access_token(self)
267 return token_info
268 except requests.exceptions.HTTPError as http_error:
--> 269 self._handle_oauth_error(http_error)
270
271 def _add_custom_values_to_token_info(self, token_info):
C:\usr\Miniconda3\lib\site-packages\spotipy\oauth2.py in _handle_oauth_error(self, http_error)
144 error_description = None
145
--> 146 raise SpotifyOauthError(
147 'error: {0}, error_description: {1}'.format(
148 error, error_description
SpotifyOauthError: error: invalid_client, error_description: Failed to get client
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 20 (10 by maintainers)
Have you also confirmed that your app can also access the client secret? Furthermore, I must admit that, if you’re still getting an
invalid_clienterror, then I’m still not confident thatspotipycan access both the client id and client secret. For the sake of simplicity if nothing else, you should initialize your instance ofSpotifyas follows. (check if you have extraneous whitespace in yourclient_idandclient_secretvariables.)The Spotify web API has multiple authorization flows (see this article).The Client Credentials Flow does not support authorizing with a user, and so can not be used with endpoints that access/modify user data. It says that right at the top of the page you linked:
spotipydoes support this authorization method too: https://github.com/spotipy-dev/spotipy/blob/572195617b3d63f05f4083a4067fe6eb0dfe448b/spotipy/oauth2.py#L160If you want you authorize with a user, you must open a URL in the browser. Period. All of the authorization flows that support authorizing with a user require opening a URL in the browser. The reason for this is simple: The Spotify user must be given a chance to login to their Spotify account and grant your app permission to access/modify their data. They can’t login to their account directly in your app because then you could steal their username and password, so they have to login on the browser.