Announcements

Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

Persistent "Invalid Client" Error

Persistent "Invalid Client" Error

Plan

Premium Family

Country

Canada

Device

Raspberry Pi 3B+

Operating System

Raspbian 11

 

My Question or Issue

I've created an app in the Developer Dashboard for a device I've created that uses a raspberry pi. However, when I try to authenticate the client/device, I get the following error:

 

Traceback (most recent call last):
File "/usr/local/lib/python3.9/dist-packages/spotipy/oauth2.py", line 588, in refresh_access_token
response.raise_for_status()
File "/usr/lib/python3/dist-packages/requests/models.py", line 943, 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 "/home/pi/Desktop/QPTestScripts/getDevices.py", line 12, in <module>
devices = sp.devices()
File "/usr/local/lib/python3.9/dist-packages/spotipy/client.py", line 1748, in devices
return self._get("me/player/devices")
File "/usr/local/lib/python3.9/dist-packages/spotipy/client.py", line 323, in _get
return self._internal_call("GET", url, payload, kwargs)
File "/usr/local/lib/python3.9/dist-packages/spotipy/client.py", line 247, in _internal_call
headers = self._auth_headers()
File "/usr/local/lib/python3.9/dist-packages/spotipy/client.py", line 238, in _auth_headers
token = self.auth_manager.get_access_token(as_dict=False)
File "/usr/local/lib/python3.9/dist-packages/spotipy/oauth2.py", line 525, in get_access_token
token_info = self.validate_token(self.cache_handler.get_cached_token())
File "/usr/local/lib/python3.9/dist-packages/spotipy/oauth2.py", line 380, in validate_token
token_info = self.refresh_access_token(
File "/usr/local/lib/python3.9/dist-packages/spotipy/oauth2.py", line 596, in refresh_access_token
self._handle_oauth_error(http_error)
File "/usr/local/lib/python3.9/dist-packages/spotipy/oauth2.py", line 146, in _handle_oauth_error
raise SpotifyOauthError(
spotipy.oauth2.SpotifyOauthError: error: invalid_client, error_description: Invalid client

 

I've verified that the client ID, client secret, and redirect URI match what is in the app in the developer dashboard, and I've also checked that the scopes are correct. How can I resolve this issue? Your help is much appreciated!

 

 

 

 

Reply
3 Replies

I think you are using Client Credentials, but maybe the endpoint you are trying to use requires User Authentication. (Is an assumption, because you haven't posted any code, and I can't figure it out with the error message alone.)

If you can't authenticate on the Pi, you can run the script on your desktop, login, and copy the .cache file to the directly the script is run from.

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

Hi Ximzend,

 

Thank you so much for your reply! Here is the script that I'm trying to run to authenticate the pi and simply get the device ID:

 

import spotipy
from spotipy.oauth2 import SpotifyOAuth

# Set up the Spotipy client with your credentials


sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id='<my_client_ID>', client_secret='<my_client_secret>', redirect_uri='https://example.com/callback/', scope='user-read-playback-state, user-modify-playback-state', open_browser=False))


# Retrieve the list of available devices
devices = sp.devices()

# Iterate over the devices and print their details
for device in devices['devices']:
device_name = device['name']
device_id = device['id']
device_type = device['type']
print(f"Device Name: {device_name}, Device ID: {device_id}, Device Type: {device_type}")

 

I've input the actual client secret and ID in my code and made sure they match what is in the developer dashboard, along with the redirect URI. Do you have any idea what may be happening? Thank you again for your help!

Your code works for me, but I had to copy and go to the URL displayed in the console, log in, and past the resulting URL back in the console. This is caused by the open_browser=False.

You can try to remove the .cache file from the active running directory and run the script again.

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

Suggested posts

Let's introduce ourselves!

Hey there you,   Yeah, you! 😁   Welcome - we're glad you joined the Spotify Community!   While you here, let's have a fun game and get…

ModeratorStaff / Moderator/ 4 years ago  in Social & Random