mopidy / mopidy-spotify

Mopidy extension for playing music from Spotify
https://mopidy.com/ext/spotify/
Apache License 2.0
933 stars 109 forks source link

`data` is `None` in `valid_web_data` #246

Closed jodal closed 4 years ago

jodal commented 4 years ago

Running Mopidy-Spotify 4.0.0a3. Happened during Mopidy startup.

ERROR    2019-12-21 11:14:19,165 [26675:SpotifyBackend-10] pykka
  Unhandled exception in SpotifyBackend (urn:uuid:9f4a299d-1e0c-47da-a621-fb54c46eb927):
Traceback (most recent call last):
  File "/home/jodal/dev/virtualenvs/mopidy3/lib/python3.7/site-packages/pykka/_actor.py", line 186, in _actor_loop
    self.on_start()
  File "/home/jodal/mopidy-dev/mopidy-spotify/mopidy_spotify/backend.py", line 68, in on_start
    self.playlists.refresh()
  File "/home/jodal/mopidy-dev/mopidy-spotify/mopidy_spotify/playlists.py", line 64, in refresh
    self._get_playlist(playlist_ref.uri)
  File "/home/jodal/mopidy-dev/mopidy-spotify/mopidy_spotify/playlists.py", line 52, in _get_playlist
    as_items,
  File "/home/jodal/mopidy-dev/mopidy-spotify/mopidy_spotify/playlists.py", line 95, in playlist_lookup
    as_items=as_items,
  File "/home/jodal/mopidy-dev/mopidy-spotify/mopidy_spotify/translator.py", line 223, in to_playlist
    for web_track in web_tracks
  File "/home/jodal/mopidy-dev/mopidy-spotify/mopidy_spotify/translator.py", line 223, in <listcomp>
    for web_track in web_tracks
  File "/home/jodal/mopidy-dev/mopidy-spotify/mopidy_spotify/translator.py", line 307, in web_to_track
    ref = web_to_track_ref(web_track)
  File "/home/jodal/mopidy-dev/mopidy-spotify/mopidy_spotify/translator.py", line 184, in web_to_track_ref
    if not valid_web_data(web_track, "track"):
  File "/home/jodal/mopidy-dev/mopidy-spotify/mopidy_spotify/translator.py", line 172, in valid_web_data
    return data.get("type") == object_type and "uri" in data
AttributeError: 'NoneType' object has no attribute 'get'
ERROR    2019-12-21 11:14:19,168 [26675:MainThread] mopidy.commands
  Actor died: SpotifyBackend (urn:uuid:9f4a299d-1e0c-47da-a621-fb54c46eb927) stopped before handling the message
kingosticks commented 4 years ago

I don't see how this happens so I am a bit stuck to test it.

jodal commented 4 years ago

Refresh has worked before and after, so it must have been a glitch from the Spotify API. I guess this change should be enough to guard against it:

 diff --git a/mopidy_spotify/translator.py b/mopidy_spotify/translator.py
index 5ff7d28..c7d3ea8 100644
--- a/mopidy_spotify/translator.py
+++ b/mopidy_spotify/translator.py
@@ -169,7 +169,7 @@ def to_track_ref(sp_track):

 def valid_web_data(data, object_type):
-    return data.get("type") == object_type and "uri" in data
+    return data and data.get("type") == object_type and "uri" in data

 def to_track_refs(sp_tracks, timeout=None):