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
74.05k stars 31.08k forks source link

Spotify' object has no attribute 'playlist' #31582

Closed pergolafabio closed 4 years ago

pergolafabio commented 4 years ago

The problem

Environment

Problem-relevant configuration.yaml

spotify:
  client_id: !secret spotify_id
  client_secret: !secret spotify_secret

Traceback/Error logs

2020-02-07 11:29:48 ERROR (MainThread) [homeassistant.helpers.entity] Update for media_player.spotify fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 279, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 461, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/spotify/media_player.py", line 83, in wrapper
    result = func(self, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/components/spotify/media_player.py", line 338, in update
    self._playlist = self._spotify.playlist(current["context"]["uri"])
AttributeError: 'Spotify' object has no attribute 'playlist'
pergolafabio commented 4 years ago

@frenck , can you have a look at it, not urgent :-)

probot-home-assistant[bot] commented 4 years ago

Hey there @frenck, mind taking a look at this issue as its been labeled with a integration (spotify) you are listed as a codeowner for? Thanks!

springstan commented 4 years ago

@pergolafabio have you followed the documentation and activated your account?

Waseh commented 4 years ago

I'm having similar issues with the new integration. Rolling back the old integration still works as expected. I even created a new application on Spotify Dev to no avail.

pergolafabio commented 4 years ago

@pergolafabio have you followed the documentation and activated your account?

Yeah, folllwed new installation steps, all is working and authorized with new callback url... Everything also works as expected, just my log file is flooding when I am listening to spotify

springstan commented 4 years ago

@pergolafabio on which device are you playing the music? Please describe the problem more thoroughly and add it to the issue.

pergolafabio commented 4 years ago

I am playing it on a Denon receiver with Spotify connect

pergolafabio commented 4 years ago

i now tried the spotify webplayer, as soon as a start playing on my laptop, the error mesagges are beginning

JuanitoAlimana commented 4 years ago

Pffffff,

El dom., 9 de feb. de 2020, 3:51 a. m., pergolafabio < notifications@github.com> escribió:

i now tried the spotify webplayer, as soon as a start playing on my laptop, the error mesagges are beginning

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/home-assistant/home-assistant/issues/31582?email_source=notifications&email_token=AKU5V2POKYACSFKNS3UX343RB67XXA5CNFSM4KRMFV62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELGGMMI#issuecomment-583820849, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKU5V2IPG7CV5DAECNJL64LRB67XXANCNFSM4KRMFV6Q .

frenck commented 4 years ago

Thanks for reporting this in guys. I'll take a look if I can see what is going on.

pergolafabio commented 4 years ago

Thnx in advance, am I the only one with issue? Since no one else is reply ing

roflcoopter commented 4 years ago

I also have this issue, however it only affects one of my accounts, the other one works fine

holnburger commented 4 years ago

I'm also having this issue. Spotify is sometimes not available and when its available would say it's idle, even though it's currently playing.

grafik

spotify: Error on device update! Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 304, in _async_add_entity await entity.async_device_update(warning=False) File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 461, in async_device_update await self.hass.async_add_executor_job(self.update) File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/usr/src/homeassistant/homeassistant/components/spotify/media_player.py", line 83, in wrapper result = func(self, *args, **kwargs) File "/usr/src/homeassistant/homeassistant/components/spotify/media_player.py", line 338, in update self._playlist = self._spotify.playlist(current["context"]["uri"]) AttributeError: 'Spotify' object has no attribute 'playlist'

frenck commented 4 years ago

The problem for me right now, is that I'm unable to reproduce this.

I've tried the following:

I've repeated the above for the following as well:

(and a bunch of combinations from above).

pergolafabio commented 4 years ago

my testings are with a premium account, testing when i start a playlist from chrome or if i use the receiver

what can i do to test or provide you more info ?

Waseh commented 4 years ago

@frenck i'm not sure if my problem is related however i can't get the new integration to work either. I end up getting this error everytime i start playback from a device

Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 424, in _async_add_entity await entity.async_update_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 284, in async_update_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 327, in _async_write_ha_state attr.update(self.state_attributes or {}) File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 793, in state_attributes for attr in ATTR_TO_PROPERTY File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 794, in <dictcomp> if getattr(self, attr) is not None File "/usr/src/homeassistant/homeassistant/components/spotify/media_player.py", line 160, in media_content_id return self._currently_playing.get("item", {}).get("name") AttributeError: 'NoneType' object has no attribute 'get'

frenck commented 4 years ago

No that is not related, @Waseh. Please don't stack things in a single issue. Please open up a separate issue for that. 👍

frenck commented 4 years ago

AttributeError: 'Spotify' object has no attribute 'playlist'

This error made me think. playlist is not an attribute to the Spotify object, but a method. So that message makes no sense. The only reason why Python would throw that error is when the methods & attributes both don't exist.

But that makes no sense, since well.. the method is hardcoded in the codebase, and thus cannot be missing.

This method, however, was introduced in Spotipy (the library used) 2.6.0+. The current version used by the integration is 2.7.1. The previous version of the integration did have an older version, which indeed does not have the playlist method.

So, that makes me think, do you guys have a possibly older version? Are you using a custom component or integration that does something with Spotify? Maybe an issue with a virtual environment (if used)?

pergolafabio commented 4 years ago

i have indeed this sensor : https://github.com/dnguyen800/spotify-playlist-sensor

and also playing with those 2 cards as a test: https://github.com/dnguyen800/spotify-playlist-card and https://github.com/custom-cards/spotify-card

holnburger commented 4 years ago

Are you using a custom component or integration that does something with Spotify?

I did. I also just recently installed the spotify-playlist-sensor. I uninstalled it but now the integration doesn't list an entity to integrate.

grafik

I'm using Home Assistant via Docker running on Ubuntu 18.04.

pergolafabio commented 4 years ago

I am going to unload the custom and try again this evening, keep you posted...

pergolafabio commented 4 years ago

But maybe if I comment the sensor, maybe the spotipy will not update?

frenck commented 4 years ago

This custom component: https://github.com/dnguyen800/spotify-playlist-sensor Will cause these issues for sure.

holnburger commented 4 years ago

Uninstalled the custom component and also the two lovelace cards that @pergolafabio also used. Restarted Home Assistant a few times, reinitiated the integration a few times. But even with spotify-playlist-sensor removed I still got the error message from the beginning.

AttributeError: 'Spotify' object has no attribute 'playlist' in the logs.

media_player.spotify stuck in unavailable state

frenck commented 4 years ago

@holnburger If you are on Home Assistant Supervised or Operating System (previously called Hass.io), you will need to rebuild the core container to get rid of it.

hassio ha rebuild from the SSH add-on console.

roflcoopter commented 4 years ago

I don't think that is the issue in my case. I'm running in docker and pip show spotipy outputs this

bash-5.0# pip show spotipy 
Name: spotipy
Version: 2.7.1
Summary: A light weight Python library for the Spotify Web API
Home-page: http://spotipy.readthedocs.org/
Author: @plamere
Author-email: paul@echonest.com
License: LICENSE.md
Location: /usr/local/lib/python3.7/site-packages
Requires: six, requests
Required-by: 
pergolafabio commented 4 years ago

I will try the custom component, with a changed requirement manually to new spotipy, that should resolve also?

frenck commented 4 years ago

@roflcoopter pip show spotipy-homeassistant ? That would be the conflicting package.

@pergolafabio The problem is that the original spotipy-homeassistant might still be installed at that point.

pergolafabio commented 4 years ago

Ok, I will try and keep you posted... But that custom one should be updated with new requirement anyway? I'll create an issue there then

roflcoopter commented 4 years ago

@roflcoopter pip show spotipy-homeassistant ? That would be the conflicting package.

@pergolafabio The problem is that the original spotipy-homeassistant might still be installed at that point.

Bingo, Recreated my container and now it works

pergolafabio commented 4 years ago

Still with that custom installed?

holnburger commented 4 years ago

@holnburger If you are on Home Assistant Supervised or Operating System (previously called Hass.io), you will need to rebuild the core container to get rid of it.

hassio ha rebuild from the SSH add-on console.

This did solve it! It's working again! Thank you

/edit: Uninstalled the custom components before rebuilding.

pergolafabio commented 4 years ago

i did a rebuild, it was succesfull allthough issie is still happening

i cant do a pip ... , running hassos here, pip not found

pergolafabio commented 4 years ago

what are my best steps? unload the custom, restart hassos, rebuid, then load custom again?

frenck commented 4 years ago

You can't use the custom @pergolafabio, it will break things.

pergolafabio commented 4 years ago

Crap, what needs to be done at the custom component to not have those errors then?

frenck commented 4 years ago

Contact the custom component creator? This is really out of scope for me and/or Home Assistant. We don't support custom integrations in general.

pergolafabio commented 4 years ago

Ok, Will do

Thnx in advance for the feedback

pergolafabio commented 4 years ago

@frenck maybe off-topic, but isn't it possible maybe with the new integration you created to retrieve the playlists from Spotify, that's what the custom does... So then maybe we don't need the custom anymore at all