Spotify configuration error (INVALID_CLIENT: Failed to get client)

http:
   base_url: http://mydomain.ddns.net:8123

media_player:
  - platform: spotify
    client_id: xxx
    client_secret: xxx

spotify app redirect URI: http://mydomain.ddns.net:8123/api/spotify

I get this error at startup:

Error while setting up platform spotify
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 150, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/spotify/media_player.py", line 111, in setup_platform
    token_info = oauth.get_cached_token()
  File "/srv/homeassistant/lib/python3.6/site-packages/spotipy/oauth2.py", line 132, in get_cached_token
    token_info = json.loads(token_info_string)
  File "/usr/local/lib/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.6/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Any hint?

edit: changed the title to reflect my current state, as wrote in this post

I assume you followed this guide to set it up?

Are you using SSL? if so you need to change http to https.
Which version of home assistant are you using?

At which step did you get this error? You created an app in Spotify Developer, added the config to your configuration.yaml and then you received this error after restart?

Yes I followed that guide.
No SSL.
Home Assistant 0.100.1, virtual environment installation.
Spotify app with the URI mentioned above.

At Home Assistant restart I get that error.

Hmm that seems strange.
I would double check the URI, id and password. Delete the spotify token if any has been created and try it again.

digging down into the error I found that it was triggered when oauth in media_player.py takes the cached token as input.

I don’t understand where the .spotify-token-cache file is saved, so I modified media_player.py at line 43 in this way:
DEFAULT_CACHE_PATH = ".spotify-token-cache_MODIFIED"

Then it went through the normal authorization process, but the output I get is this one:
INVALID_CLIENT: Failed to get client

redirected URL after clicking authorization link: https://accounts.spotify.com/authorize?client_id=MYID&response_type=code&redirect_uri=http%3A%2F%2FMYDOMAIN.ddns.net%3A8123%2Fapi%2Fspotify&scope=user-modify-playback-state+user-read-playback-state+user-read-private

And you are able to access your home assistant instance from outside with the ddns url?

yes the ddns url is working fine, I even use it in the iOS companion app from outside my home network

You can’t just change the path for the spotify token cache file. The token file will be in the main configuration path and the file is called “.spotify-token-cache”, so if you change this the app will not be able to find the file and therefore it will not be able to authorize.

There has never been a .spotify-token-cache in /home/homeassistant/.homeassistant

In my previous testing I tried also to completely reset the app’s secrets, and it started giving the JSONDecodeError: my guess was that the information relative to the previous app’s secrets was cached somewhere, so I tried to point media_player.py to another, non-existent, cache file, and that worked because I was able to repeat the normal procedure from scratch.

After doing that I undid the modification, I’m staying with my current app’s secrets, but I don’t see a file called .spotify-token-cache anywhere, and I get the “INVALID_CLIENT: Failed to get client” error as mentioned above.

Normally this file will be generated once you do the authorization process in home assistant. That’s why it seems strange to me taht you get this error before you even start the authorization process.

To be clear, that webpage with that error appears after having logged in with my Spotify account in the Spotify login page that appears.

hmm version .106 installed on Feb 26 2020 seems to cause some problems with bot ring and spotify. Spotify was working before but stopped to do so, log indicates a platform setup, bit it is not im my config.
Ring eems to be working normal with the same error

## Log Details (ERROR)

Logger: homeassistant.components.media_player
Integration: Media player ([documentation](https://www.home-assistant.io/integrations/media_player), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+media_player%22))
First occured: 4:47:59 PM (1 occurences)
Last logged: 4:47:59 PM

The spotify platform for the media_player integration does not support platform setup. Please remove it from your config.

noticed that spotify integration changed, you have to change redirect urls in the sportify app aswell.

configuration.yaml

spotify:
  client_id: YOUR_CLIENT_ID
  client_secret: YOUR_CLIENT_SECRET

Spotify app
image

Hi All,

I’m still getting this issue.

INVALID_CLIENT: Failed to get client

As soon as i add the integration.

I’ve removed my code from the YAML and i’ve created a new app on the dashboard.

Any ideas?

2 Likes

I have he same issue as well. I upgraded to 2022.8, got the warning, removed the line from YAML. Tried installing Spotify app and got this as warning every time.
Steps I tried:

nothing seem to work and all result in the same error: INVALID_CLIENT: Failed to get client.

I have no clue where to look anymore. I run Home Assistant supervised through Docker on a Debian bullseye machine.

can anyone help?

same problem…

Had the same problem. Today I managed to solve it. I changed the instance spotify integration
url to my internal ip and port:

YESSSSS I found it…

in home assistant, go to Terminal (install if you don’t have it),

  • cd .. (go one folder back)
  • cd config
  • ls -a (you will see .storage in the list (with only ls you won’t see the hidden folders)
  • cd .storage/
  • ls and check if you see application_credentials
    • I opened it with nano application_credentials and there are spotify credentials (crtl x to get out)
  • cp application_credentials application_credentialsold (just to be sure you have them in case, you can skip this step if you are sure)
  • rm application_credentials
  • ls to check if the file is gone.
  • restart home assistant.
  • Add Spotify as described in Spotify - Home Assistant
  • if you go back to the file in .storage you will see a new file is created with your new credentials/codes.

I hope this helps for all of you.

26 Likes

Hi there, I have the same issue but I am not familiar with using Terminal. Could you please put the above instructions in newbie format? Thanks

2 Likes

There are instructions for installing terminal and ssh here:

Only difference is that home assistant changed some things/location. Go to settings, add-ons, add-ons store, look for terminal & ssh and install it. After install click open web-ui. Then follow the instructions I made already.

1 Like