Announcements

Help Wizard

Step 1

NEXT STEP

Frustrating SpotifyOauthError: Invalid Client

Frustrating SpotifyOauthError: Invalid Client

Hi, I've repeatedly checked the client_id and client_secret values with those displayed on the developer dashboard. The values are identical. I only ever copy and paste.

clientID = os.environ['client_id']
clientSecret = os.environ['client_secret']

sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id=clientID,
client_secret=clientSecret,
redirect_uri="http://localhost:8888/callback",
scope="user-library-read"))

song_name = "Teen Spirit"

search_result = sp.search(q=song_name)

Any help you can offer is greatly appreciated. Thanks
Reply
4 Replies

Have you added the redirect URI to the dashboard of your app (and clicked save)?

Thanks Ximzend for taking the time to reply. I did but to no avail.

 

Traceback (most recent call last):
File "/Users/namofuser/PycharmProjects/pythonProject/pythonProject/spotifyProject/venv/lib/python3.10/site-packages/spotipy/oauth2.py", line 588, in refresh_access_token
response.raise_for_status()
File "/Users/namofuser/PycharmProjects/pythonProject/pythonProject/spotifyProject/venv/lib/python3.10/site-packages/requests/models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://accounts.spotify.com/api/token

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/namofuser/PycharmProjects/pythonProject/pythonProject/spotifyProject/main.py", line 100, in <module>
getSpotifyData()
File "/Users/namofuser/PycharmProjects/pythonProject/pythonProject/spotifyProject/main.py", line 65, in getSpotifyData
search_result = sp.search(q=song_name)
File "/Users/namofuser/PycharmProjects/pythonProject/pythonProject/spotifyProject/venv/lib/python3.10/site-packages/spotipy/client.py", line 585, in search
return self._get(
File "/Users/namofuser/PycharmProjects/pythonProject/pythonProject/spotifyProject/venv/lib/python3.10/site-packages/spotipy/client.py", line 321, in _get
return self._internal_call("GET", url, payload, kwargs)
File "/Users/namofuser/PycharmProjects/pythonProject/pythonProject/spotifyProject/venv/lib/python3.10/site-packages/spotipy/client.py", line 245, in _internal_call
headers = self._auth_headers()
File "/Users/namofuser/PycharmProjects/pythonProject/pythonProject/spotifyProject/venv/lib/python3.10/site-packages/spotipy/client.py", line 236, in _auth_headers
token = self.auth_manager.get_access_token(as_dict=False)
File "/Users/namofuser/PycharmProjects/pythonProject/pythonProject/spotifyProject/venv/lib/python3.10/site-packages/spotipy/oauth2.py", line 525, in get_access_token
token_info = self.validate_token(self.cache_handler.get_cached_token())
File "/Users/namofuser/PycharmProjects/pythonProject/pythonProject/spotifyProject/venv/lib/python3.10/site-packages/spotipy/oauth2.py", line 380, in validate_token
token_info = self.refresh_access_token(
File "/Users/namofuser/PycharmProjects/pythonProject/pythonProject/spotifyProject/venv/lib/python3.10/site-packages/spotipy/oauth2.py", line 596, in refresh_access_token
self._handle_oauth_error(http_error)
File "/Users/namofuser/PycharmProjects/pythonProject/pythonProject/spotifyProject/venv/lib/python3.10/site-packages/spotipy/oauth2.py", line 146, in _handle_oauth_error
raise SpotifyOauthError(
spotipy.oauth2.SpotifyOauthError: error: invalid_client, error_description: Invalid client

Have you tried deleting the .cache file in the directory you are running your script from?

Also, if you set/name the environment variables as followed, you don't have to specify them in your code anymore:

  • SPOTIPY_CLIENT_ID
  • SPOTIPY_CLIENT_SECRET
  • SPOTIPY_REDIRECT_URI

Then you can just use:

sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=SCOPE))

 

Note: there shouldn't be quotes around the IDs and URI around the values of the environment variables.

 

Thanks for this. I've cleared the pycharm and browser caches but the error message remains. 

Suggested posts