home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.03k stars 29.69k forks source link

Spotify Media browsing error - Invalid Spotify account specified #122211

Closed itwtds closed 2 weeks ago

itwtds commented 1 month ago

The problem

After linking multiple accounts through Spotify Developers App and adding these respective accounts to Spotify I'm now unable to browse Spotify media, I'm getting a popup stating "Invalid Spotify account specified". snippet I've tried to unlink the accounts, re-create the Spotify Developer App and reverting back to default. I've also tried to set a up both single account and multi account on another HA instance, with the same result.

The integration fetches artwork from Spotify and HA is able to control media players (Sonos) without any issues streaming from the Spotify account - it's the media browsing part that is broken. Logs seem to indicate that there is no devices returned, not sure if this is related. Otherwise it's no clear indications in the logs as to why it's failing.

Happy to debug if needed.

Thanks.

What version of Home Assistant Core has the issue?

core-2024.7.2 / core-2024.7.3

What was the last working version of Home Assistant Core?

core-2024.7.2

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Spotify

Link to integration documentation on our website

https://www.home-assistant.io/integrations/spotify/

Diagnostics information

diag.txt

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

Tested system restore and upgrade, cleared all integration data and credentials.

home-assistant[bot] commented 1 month ago

Hey there @frenck, @joostlek, mind taking a look at this issue as it has been labeled with an integration (spotify) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `spotify` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign spotify` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


spotify documentation spotify source (message by IssueLinks)

Blck41 commented 1 month ago

I have the same issue. Has never worked since fresh HA install.

PorkyZN commented 1 month ago

Yip, same issue for me, tried to unlink and re-link but still get the same error.

RomainKB commented 1 month ago

Same issue for me, I tried to install spotify on a fresh HA deshboard for the first time. No issue with the link account part but then I get the error message when trying to browse media

bexem commented 1 month ago

Same issue, "Invalid Spotify account specified" for both my account and my partner's. Both premium if that matters. It used to work just fine. Tried with re-adding the integration, the credential and rolling the secrets. I'm running the latest official docker container.

stuartbike commented 1 month ago

Hi I'm a new user and I have the same problem. I thought it was just me but maybe it's the same issue. Invalid Spotify account specified

dummyax commented 1 month ago

I have the same issue with a new installation. Have worked fine before.

ctgTX commented 1 month ago

Glad im not the only one...

ljump12 commented 1 month ago

New user, but have not got it working here either. Same issue.

matthewchubb commented 1 month ago

same here, not woked since fresh install

midnightoil2 commented 1 month ago

Same issue, integration was configured and working prior to updates around 3 releases back. Running latest core 2024.7.3, suervisor 2024.06.2.

TommyUSB commented 1 month ago

The same issue with a new installation core 2024.7.3

CarlatanY commented 1 month ago

I have the same problem

Yoruio commented 1 month ago

same here

Hesti85 commented 1 month ago

Same Problem here

miketarg commented 4 weeks ago

Screenshot 2024-08-07 17 53 01 same issue, tried removing and reinstalling , makes no difference please can we get an update on this as its very frustrating.

miketarg commented 4 weeks ago

I have updated to the latest ha core, still doesn't work Screenshot_20240808-093558

Is there any information I can give to assist?

RevoSunrise commented 4 weeks ago

Same issue with CORE 2024.8.0

Gecko-with-a-hat commented 3 weeks ago

Had it working fine for months. Today I tried adding my wife's account and I got the "Invalid Spotify account specified" message when trying to browse anything from her account. I got fed up and removed the integration and now I also get that error on my own account after re-adding it.

mattred33 commented 3 weeks ago

I had the same issue, but I believe it has to do with the Spotify player not recognizing the audio output sources.

I can get Spotify to play via HA if I go into Media and select Spotify as the playback destination in the bottom right corner. However, every other device/destination will say "Invalid Spotify account specified"

It's not a new install, it worked prior to 2024.8, and just randomly broke one day (I don't believe I did any updates around the time it broke).

JimRnewell commented 3 weeks ago

same issue here

sirs2k commented 3 weeks ago

Add me to the list :(

cr4zyhead commented 3 weeks ago

Same probleme here, i reinstall the integratrion without result

elnorte13524 commented 3 weeks ago

Same issue here. Any time I try to browse spotify for any of my google or sonos speakers I get the same error. I have 2 premium accounts integrated that worked fine for ages.

Randomly a couple of nights ago both of my spotify accounts saw "suspicious activity", locked the accounts pending a password change. HA is the only thing that sees both accounts. After I finally got them rebuilt from scratch, I now can't play Spotify on any of my media players.

Hoping there's a fix on the way soon, this is short frustrating.

mattred33 commented 3 weeks ago

Randomly a couple of nights ago both of my spotify accounts saw "suspicious activity", locked the accounts pending a password change. HA is the only thing that sees both accounts. After I finally got them rebuilt from scratch, I now can't play Spotify on any of my media players.

this is also what triggered the issue for me. After I reset my password, HA broke.

djansen1987 commented 3 weeks ago

Same issues, was logged out from spotify on all devices for some reason by spotify. When i tried to login again everyting works except the media browser. removed the application credentials and integration. THen i see it being removed from the media browser as well. Later add the integration back, the spotify button also appears in the media browser but when clicking it i get the same error. Also the logs don't show anything about this.

As this also seems to linked for me to the sonos speakers, i also removed the spotify connection in the sonos app, removed the sonos integration in HA and added them back which did not solve.

yanhorobin97 commented 3 weeks ago

Same issues, was logged out from spotify on all devices for some reason by spotify. When i tried to login again everyting works except the media browser. removed the application credentials and integration. THen i see it being removed from the media browser as well. Later add the integration back, the spotify button also appears in the media browser but when clicking it i get the same error. Also the logs don't show anything about this.

As this also seems to linked for me to the sonos speakers, i also removed the spotify connection in the sonos app, removed the sonos integration in HA and added them back which did not solve.

Same issue here with Sonos. Tried everything it feels like

kksligh commented 3 weeks ago

following - same

seroja commented 2 weeks ago

Same for me - following

ChalidNL commented 2 weeks ago

Since the release of Friday it is working

bradydjohnson commented 2 weeks ago

New HA install, same problem.

Fatalmose commented 2 weeks ago

Yes… Same problem for me… Non of my media players using Spotify on Spotcast aren’t working anymore… Invalid Spotify Account…

mazzok1975 commented 2 weeks ago

New HA install, some problem

Zeronozero commented 2 weeks ago

Same here unfortunately

BobbynBR commented 2 weeks ago

Ditto...getting same issue

anandsathy commented 2 weeks ago

Same issue here.

djansen1987 commented 2 weeks ago

As owner of the sonos integration @jjlawren @PeteRager

As owner of the spotify integration @joostlek @frenck

Are you guys able to help with this issue?

PeteRager commented 2 weeks ago

My understanding is the issue is with browsing Spotify. These go through the spotify integration.

PeteRager commented 2 weeks ago

The error comes from this section of code:

https://github.com/home-assistant/core/blob/1fdcbc3f1550b049dc47540a5f581180edf18b11/homeassistant/components/spotify/browse_media.py#L176-L181

Which kind of looks like its an internal problem and it's never actually going out to spotify.

I think the problem was introduced by this PR as this is where the checks originate. It was merged end of May which corresponds to the timeline of it failing in 2024.7.x

https://github.com/home-assistant/core/pull/117037

I don't have a spotify account, if someone want to donate one temporarily I can see if i can repro in the debugger

You could try commenting out line 181 and see if it starts working. That would indicate that the type check on 179 is faulty. If it still fails then the attempt to retrieve it on line 178 is faulty. It sounds like the way credentials are stored has changed and when you update they are stored in a different way. If you have a backup of your .storage directory from when it did work an compare between the backup directory and current contents should show the shift.

bart-vs commented 2 weeks ago

Same problem here, after using Spotify in HA for more then 16 months without any problems.

I had a problem since last Friday. I could no longer log in to Spotify because my password no longer met the new stricter password requirement from Spotify. My password still consisted of 8 characters and the new requirement was at least 10 characters with capital letters and numbers. So I changed the password to Spotify's new standards and I could log in again. I thought I would simply change my password at HA, by deleting old data and adding new ones. But this no longer worked. Just like everyone else here, I now get the message:

"Invalid Spotify account specified"

I look forward to a solution.

itwtds commented 2 weeks ago

You could try commenting out line 181 and see if it starts working. That would indicate that the type check on 179 is faulty. If it still fails then the attempt to retrieve it on line 178 is faulty. It sounds like the way credentials are stored has changed and when you update they are stored in a different way. If you have a backup of your .storage directory from when it did work an compare between the backup directory and current contents should show the shift.

Thanks for checking. I commented out line 181 and rearranged the the code for indentation and it throws the following error:

sp

Log;

Logger: homeassistant.components.websocket_api.http.connection Source: components/spotify/browse_media.py:183 integration: Home Assistant WebSocket API (documentation, issues) First occurred: 8:46:57 PM (2 occurrences) Last logged: 8:47:00 PM

[140164256687456] Error handling message: Unknown error (unknown_error) (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36) Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 28, in _handle_async_response await func(hass, connection, msg) File "/usr/src/homeassistant/homeassistant/components/media_player/init.py", line 1304, in websocket_browse_media payload = await player.async_browse_media(media_content_type, media_content_id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/sonos/media_player.py", line 776, in async_browse_media return await media_browser.async_browse_media( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/sonos/media_browser.py", line 141, in async_browse_media return await spotify.async_browse_media( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/spotify/browse_media.py", line 183, in async_browse_media info = entry.runtime_data ^^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'runtime_data'


I did a quick diff on /config/.storage/application_credentials from an earlier known working backup to the current setup and it looks identical. I'm happy to pass you the credentials to my account if you'd like to test firsthand, just let me know your preferred way of communication and we'll get it set up.

Thanks

PeteRager commented 2 weeks ago

Thanks. That means it isn't finding the config_entry. I just created a free account will see if I can get it setup, if that doesn't work I'll take you up on your offer.

PeteRager commented 2 weeks ago

I think I got it fixed. The host name is mixed case but config entries are all upper case. Try replacing that section of code with this:

It adds .upper() to the host to make it upper case. That gets me beyond the error and i can see the spotify playlist i created

    if (
        parsed_url.host is None
        or (entry := hass.config_entries.async_get_entry(parsed_url.host.upper())) is None
        or not isinstance(entry.runtime_data, HomeAssistantSpotifyData)
    ):
PeteRager commented 2 weeks ago

I did a quick diff on /config/.storage/application_credentials from an earlier known working backup to the current setup and it looks identical. I'm happy to pass you the credentials to my account if you'd like to test firsthand, just let me know your preferred way of communication and we'll get it set up.

Take a look at core.config_entries in the backup vs the current version. I'd like to see what the entry looked like that worked (you can delete the secret keys) vs what the entry looks like now. Since it worked until you regen'd the credentials, I am concerned that the fix may break existing entries that haven't been updated.

itwtds commented 2 weeks ago

I think I got it fixed. The host name is mixed case but config entries are all upper case. Try replacing that section of code with this:

It adds .upper() to the host to make it upper case. That gets me beyond the error and i can see the spotify playlist i created

    if (
        parsed_url.host is None
        or (entry := hass.config_entries.async_get_entry(parsed_url.host.upper())) is None
        or not isinstance(entry.runtime_data, HomeAssistantSpotifyData)
    ):

This looks promising! I'm able to fully browse and play media directly. Looks ready for PR.

Thanks for helping out.

itwtds commented 2 weeks ago

I did a quick diff on /config/.storage/application_credentials from an earlier known working backup to the current setup and it looks identical. I'm happy to pass you the credentials to my account if you'd like to test firsthand, just let me know your preferred way of communication and we'll get it set up.

Take a look at core.config_entries in the backup vs the current version. I'd like to see what the entry looked like that worked (you can delete the secret keys) vs what the entry looks like now. Since it worked until you regen'd the credentials, I am concerned that the fix may break existing entries that haven't been updated.

OLD { "entry_id": "", <<--- lower case "version": 1, "minor_version": 1, "domain": "spotify", "title": "Spotify 1", "data": { "authimplementation": "spotify", "token": { "access_token": "", "token_type": "Bearer", "expires_in": 3600, "refresh_token": "", "scope": "playlist-read-private playlist-read-collaborative user-modify-playback-state user-library-read user-follow-read user-read-playback-state user-read-recently-played user-read-playback-position user-read-private user-top-read", "expires_at": 1716588812.6715796 }, "id": "", "name": "Spotify 1" }, "options": {}, "pref_disable_new_entities": false, "pref_disable_polling": false, "source": "user", "unique_id": "", "disabled_by": null },

-- NEW { "created_at": "2024-08-19T21:24:35.484636+00:00", "data": { "authimplementation": "spotify", "token": { "access_token": "" "token_type": "Bearer", "expires_in": 3600, "refresh_token": "", "scope": "playlist-read-private playlist-read-collaborative user-modify-playback-state user-library-read user-follow-read user-read-playback-state user-read-recently-played user-read-playback-position user-re "expires_at": 1724106275.389254 }, "id": "", "name": "Spotify 1" }, "disabled_by": null, "domain": "spotify", "entry_id": "", <<--- Upper case "minor_version": 1, "modified_at": "2024-08-19T21:24:35.484638+00:00", "options": {}, "pref_disable_new_entities": false, "pref_disable_polling": false, "source": "user", "title": "Spotify 1", "unique_id": "", "version": 1 },

--

Valid point. So having a look at core.config_entries I see that "entry_id" now contains an upper case value whereas the backup was stored in lower case.

Just for reference - I deleted the integration, wiped the app credentials, restarted HA and the linked two separate accounts. It's working without any issues.

PeteRager commented 2 weeks ago

Thank you. So we know the root cause is changing of the case in the entry Id when creating a new entry. The entry Id is an internally generated GUID. At a minimum we'll need to look for the entry id in either lowercase or upper case. Perhaps we can get the host name in the URL in the correct case. Or create the entry I'd always in lowercase. I'll evaluate those three options, see what is the cleanest and get a PR put together.

Fatalmose commented 2 weeks ago

Many thanks….

JS…

Le mar. 20 août 2024 à 13:37, Pete Sage @.***> a écrit :

Thank you. So we know the root cause is changing of the case in the entry Id when creating a new entry. The entry Id is an internally generated GUID. At a minimum we'll need to look for the entry id in either lowercase or upper case. Perhaps we can get the host name in the URL in the correct case. Or create the entry I'd always in lowercase. I'll evaluate those three options, see what is the cleanest and get a PR put together.

— Reply to this email directly, view it on GitHub https://github.com/home-assistant/core/issues/122211#issuecomment-2298642450, or unsubscribe https://github.com/notifications/unsubscribe-auth/BGEH4FXRS4YGGJU37WX466TZSMS7DAVCNFSM6AAAAABLFMDPG6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJYGY2DENBVGA . You are receiving this because you commented.Message ID: @.***>

djansen1987 commented 2 weeks ago

great findings! where can i find these files and fix this my self ? (temporarily)

itwtds commented 2 weeks ago

great findings! where can i find these files and fix this my self ? (temporarily)

Depends on your setup, so going off a regular HAOS installation below;

You need to access your core container through the shell. For that you need the advanced SSH addon with protection mode turned off. Run 'docker exec -it homeassistant bash' and you should get an interactive shell. Run 'vi /usr/src/homeassistant/homeassistant/components/spotify/browse_media.py' and make the changes according to Pete's fix. :wq! Restart HA.