Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Expected length to be a <class 'int'>, not 156923.0 #375

Closed
svanrossem opened this issue Feb 27, 2024 · 8 comments · Fixed by #377
Closed

TypeError: Expected length to be a <class 'int'>, not 156923.0 #375

svanrossem opened this issue Feb 27, 2024 · 8 comments · Fixed by #377
Assignees
Labels
A-webapi Area: Spotify Web API

Comments

@svanrossem
Copy link

Today I'm receiving multiple errors when adding tracks to the queue.

ERROR    2024-02-27 12:54:10,020 [1:Core-6 (_actor_loop)] mopidy.core.library
  SpotifyBackend backend caused an exception.
Traceback (most recent call last):
  File "/opt/mopidy/lib64/python3.11/site-packages/mopidy/core/library.py", line 17, in _backend_error_handling
    yield
  File "/opt/mopidy/lib64/python3.11/site-packages/mopidy/core/library.py", line 230, in lookup
    result = future.get()
             ^^^^^^^^^^^^
  File "/opt/mopidy/lib64/python3.11/site-packages/pykka/_threading.py", line 68, in get
    raise exc_value
  File "/opt/mopidy/lib64/python3.11/site-packages/pykka/_actor.py", line 238, in _actor_loop_running
    response = self._handle_receive(envelope.message)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/mopidy/lib64/python3.11/site-packages/pykka/_actor.py", line 349, in _handle_receive
    return callee(*message.args, **message.kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/mopidy/lib64/python3.11/site-packages/mopidy_spotify/library.py", line 38, in lookup
    return lookup.lookup(self._config, self._backend._web_client, uri)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/mopidy/lib64/python3.11/site-packages/mopidy_spotify/lookup.py", line 27, in lookup
    return list(_lookup_track(config, web_client, link))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/mopidy/lib64/python3.11/site-packages/mopidy_spotify/lookup.py", line 51, in _lookup_track
    track = translator.web_to_track(web_track, bitrate=config["bitrate"])
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/mopidy/lib64/python3.11/site-packages/mopidy_spotify/translator.py", line 252, in web_to_track
    return models.Track(
           ^^^^^^^^^^^^^
  File "/opt/mopidy/lib64/python3.11/site-packages/mopidy/models/immutable.py", line 159, in __call__
    instance = super().__call__(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/mopidy/lib64/python3.11/site-packages/mopidy/models/immutable.py", line 35, in __init__
    self._set_field(key, value)
  File "/opt/mopidy/lib64/python3.11/site-packages/mopidy/models/immutable.py", line 188, in _set_field
    object.__setattr__(self, name, value)
  File "/opt/mopidy/lib64/python3.11/site-packages/mopidy/models/fields.py", line 50, in __set__
    value = self.validate(value)
            ^^^^^^^^^^^^^^^^^^^^
  File "/opt/mopidy/lib64/python3.11/site-packages/mopidy/models/fields.py", line 133, in validate
    value = super().validate(value)
            ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/mopidy/lib64/python3.11/site-packages/mopidy/models/fields.py", line 34, in validate
    raise TypeError(
TypeError: Expected length to be a <class 'int'>, not 156923.0
@kingosticks
Copy link
Member

Thanks, Spotify have randomly changed the format of their API response. Track duration_ms is supposed (and used) to be an int (https://developer.spotify.com/documentation/web-api/reference/get-track) but today it is suddenly a float! Their online developer console weirdly still shows it returning an int but I am 100% getting a float, same as you:

curl --request GET   --url 'https://api.spotify.com/v1/tracks/7HdXRMw14roDx2a0COWk3M?market=from_token'   --header 'Authorization: Bearer <REDACTED>'
{"album":{"album_type":"album","artists":[{"external_urls":{"spotify":"https://open.spotify.com/artist/74XFHRwlV6OrjEM0A2NCMF"},"href":"https://api.spotify.com/v1/artists/74XFHRwlV6OrjEM0A2NCMF","id":"74XFHRwlV6OrjEM0A2NCMF","name":"Paramore","type":"artist","uri":"spotify:artist:74XFHRwlV6OrjEM0A2NCMF"}],"external_urls":{"spotify":"https://open.spotify.com/album/6tG8sCK4htJOLjlWwb7gZB"},"href":"https://api.spotify.com/v1/albums/6tG8sCK4htJOLjlWwb7gZB","id":"6tG8sCK4htJOLjlWwb7gZB","images":[{"url":"https://i.scdn.co/image/ab67616d0000b273f633b71861897348253993f4","width":640.0,"height":640.0},{"url":"https://i.scdn.co/image/ab67616d00001e02f633b71861897348253993f4","width":300.0,"height":300.0},{"url":"https://i.scdn.co/image/ab67616d00004851f633b71861897348253993f4","width":64.0,"height":64.0}],"is_playable":true,"name":"This Is Why","release_date":"2023-02-10","release_date_precision":"day","total_tracks":10.0,"type":"album","uri":"spotify:album:6tG8sCK4htJOLjlWwb7gZB"},"artists":[{"external_urls":{"spotify":"https://open.spotify.com/artist/74XFHRwlV6OrjEM0A2NCMF"},"href":"https://api.spotify.com/v1/artists/74XFHRwlV6OrjEM0A2NCMF","id":"74XFHRwlV6OrjEM0A2NCMF","name":"Paramore","type":"artist","uri":"spotify:artist:74XFHRwlV6OrjEM0A2NCMF"}],"disc_number":1.0,"duration_ms":206700.0,"explicit":false,"external_ids":{"isrc":"USAT22215020"},"external_urls":{"spotify":"https://open.spotify.com/track/7HdXRMw14roDx2a0COWk3M"},"href":"https://api.spotify.com/v1/tracks/7HdXRMw14roDx2a0COWk3M","id":"7HdXRMw14roDx2a0COWk3M","is_local":false,"is_playable":true,"name":"This Is Why","popularity":71.0,"preview_url":"https://p.scdn.co/mp3-preview/6bef3c7dbde272bb72ea41bd3c41ee509dab94fe?cid=f88ee52f92724d51b7579a1d1cdb3128","track_number":1.0,"type":"track","uri":"spotify:track:7HdXRMw14roDx2a0COWk3M"}

Such a bunch of cowboys.

@svanrossem
Copy link
Author

Thanks, Spotify have randomly changed the format of their API response. Track duration_ms is supposed (and used) to be an int (https://developer.spotify.com/documentation/web-api/reference/get-track) but today it is suddenly a float! Their online developer console weirdly still shows it returning an int but I am 100% getting a float, same as you:

curl --request GET   --url 'https://api.spotify.com/v1/tracks/7HdXRMw14roDx2a0COWk3M?market=from_token'   --header 'Authorization: Bearer <REDACTED>'
{"album":{"album_type":"album","artists":[{"external_urls":{"spotify":"https://open.spotify.com/artist/74XFHRwlV6OrjEM0A2NCMF"},"href":"https://api.spotify.com/v1/artists/74XFHRwlV6OrjEM0A2NCMF","id":"74XFHRwlV6OrjEM0A2NCMF","name":"Paramore","type":"artist","uri":"spotify:artist:74XFHRwlV6OrjEM0A2NCMF"}],"external_urls":{"spotify":"https://open.spotify.com/album/6tG8sCK4htJOLjlWwb7gZB"},"href":"https://api.spotify.com/v1/albums/6tG8sCK4htJOLjlWwb7gZB","id":"6tG8sCK4htJOLjlWwb7gZB","images":[{"url":"https://i.scdn.co/image/ab67616d0000b273f633b71861897348253993f4","width":640.0,"height":640.0},{"url":"https://i.scdn.co/image/ab67616d00001e02f633b71861897348253993f4","width":300.0,"height":300.0},{"url":"https://i.scdn.co/image/ab67616d00004851f633b71861897348253993f4","width":64.0,"height":64.0}],"is_playable":true,"name":"This Is Why","release_date":"2023-02-10","release_date_precision":"day","total_tracks":10.0,"type":"album","uri":"spotify:album:6tG8sCK4htJOLjlWwb7gZB"},"artists":[{"external_urls":{"spotify":"https://open.spotify.com/artist/74XFHRwlV6OrjEM0A2NCMF"},"href":"https://api.spotify.com/v1/artists/74XFHRwlV6OrjEM0A2NCMF","id":"74XFHRwlV6OrjEM0A2NCMF","name":"Paramore","type":"artist","uri":"spotify:artist:74XFHRwlV6OrjEM0A2NCMF"}],"disc_number":1.0,"duration_ms":206700.0,"explicit":false,"external_ids":{"isrc":"USAT22215020"},"external_urls":{"spotify":"https://open.spotify.com/track/7HdXRMw14roDx2a0COWk3M"},"href":"https://api.spotify.com/v1/tracks/7HdXRMw14roDx2a0COWk3M","id":"7HdXRMw14roDx2a0COWk3M","is_local":false,"is_playable":true,"name":"This Is Why","popularity":71.0,"preview_url":"https://p.scdn.co/mp3-preview/6bef3c7dbde272bb72ea41bd3c41ee509dab94fe?cid=f88ee52f92724d51b7579a1d1cdb3128","track_number":1.0,"type":"track","uri":"spotify:track:7HdXRMw14roDx2a0COWk3M"}

Such a bunch of cowboys.

Do you think this is a bug from Spotify? Will they revert it or do we need a patch?

kingosticks added a commit to kingosticks/mopidy-spotify that referenced this issue Feb 27, 2024
kingosticks added a commit to kingosticks/mopidy-spotify that referenced this issue Feb 27, 2024
kingosticks added a commit to kingosticks/mopidy-spotify that referenced this issue Feb 27, 2024
@kingosticks
Copy link
Member

I expect it is a bug, they'll probably revert but might as well be robust to when they break it next time.

@kingosticks
Copy link
Member

Bugger, I need to go back and do some other places:

ERROR    2024-02-28 10:17:35,433 [6824:Core-7 (_actor_loop)] mopidy.core.library
  SpotifyBackend backend caused an exception.
Traceback (most recent call last):
  File "/home/nsteel/.virtualenvs/mopidy/lib/python3.10/site-packages/mopidy/core/library.py", line 17, in _backend_error_handling
    yield
  File "/home/nsteel/.virtualenvs/mopidy/lib/python3.10/site-packages/mopidy/core/library.py", line 194, in get_images
    if future.get() is None:
  File "/home/nsteel/.virtualenvs/mopidy/lib/python3.10/site-packages/pykka/_threading.py", line 68, in get
    raise exc_value
  File "/home/nsteel/.virtualenvs/mopidy/lib/python3.10/site-packages/pykka/_actor.py", line 238, in _actor_loop_running
    response = self._handle_receive(envelope.message)
  File "/home/nsteel/.virtualenvs/mopidy/lib/python3.10/site-packages/pykka/_actor.py", line 349, in _handle_receive
    return callee(*message.args, **message.kwargs)
  File "/home/nsteel/mopidy-dev/mopidy-spotify/mopidy_spotify/library.py", line 35, in get_images
    return images.get_images(self._backend._web_client, uris)
  File "/home/nsteel/mopidy-dev/mopidy-spotify/mopidy_spotify/images.py", line 33, in get_images
    result.update(_process_uris(web_client, uri_type, batch))
  File "/home/nsteel/mopidy-dev/mopidy-spotify/mopidy_spotify/images.py", line 121, in _process_uris
    _cache[uri["key"]] = tuple(
  File "/home/nsteel/mopidy-dev/mopidy-spotify/mopidy_spotify/images.py", line 122, in <genexpr>
    _translate_image(i) for i in item.get("images") or []
  File "/home/nsteel/mopidy-dev/mopidy-spotify/mopidy_spotify/images.py", line 130, in _translate_image
    return models.Image(uri=i["url"], height=i["height"], width=i["width"])
  File "/home/nsteel/.virtualenvs/mopidy/lib/python3.10/site-packages/mopidy/models/immutable.py", line 159, in __call__
    instance = super().__call__(*args, **kwargs)
  File "/home/nsteel/.virtualenvs/mopidy/lib/python3.10/site-packages/mopidy/models/immutable.py", line 35, in __init__
    self._set_field(key, value)
  File "/home/nsteel/.virtualenvs/mopidy/lib/python3.10/site-packages/mopidy/models/immutable.py", line 188, in _set_field
    object.__setattr__(self, name, value)
  File "/home/nsteel/.virtualenvs/mopidy/lib/python3.10/site-packages/mopidy/models/fields.py", line 50, in __set__
    value = self.validate(value)
  File "/home/nsteel/.virtualenvs/mopidy/lib/python3.10/site-packages/mopidy/models/fields.py", line 133, in validate
    value = super().validate(value)
  File "/home/nsteel/.virtualenvs/mopidy/lib/python3.10/site-packages/mopidy/models/fields.py", line 34, in validate
    raise TypeError(
TypeError: Expected height to be a <class 'int'>, not 640.0

@curiousercreative
Copy link

I hate to be a bother, but I'm hoping to recover from this quickly. @kingosticks, are you planning a release that includes this fix or would I be wise to investigate alternative solutions for running this patch?

@jodal
Copy link
Member

jodal commented Mar 1, 2024

We'll probably release a 5.0.0a1 later today.

@kingosticks
Copy link
Member

https://github.com/mopidy/mopidy-spotify/releases/tag/v5.0.0a1

@kingosticks kingosticks added the A-webapi Area: Spotify Web API label Mar 1, 2024
@kingosticks kingosticks self-assigned this Mar 1, 2024
@curiousercreative
Copy link

With the alpha release installed, my Mopidy Iris is back to working well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-webapi Area: Spotify Web API
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants