rspotify: json parse error when calling `artist` method

Describe the bug Client now returns

Bad request: json parse error: invalid type: floating point `49022656`, expected u32 at line 1 column 130: invalid type: floating point `49022656`, expected u32 at line 1 column 130

for every artist request. The reason seems to be because Spotify changes the type of followers.total and other fields to float.

To Reproduce Steps to reproduce the behavior:

  1. Run
curl --request GET \
        --url https://api.spotify.com/v1/artists/1dfeR4HaWDbWqFHLkxsg1d \
        --header 'Authorization: Bearer $TOKEN'
  1. Observe that follower.total is not an integer. Example result:
{"external_urls":{"spotify":"https://open.spotify.com/artist/1dfeR4HaWDbWqFHLkxsg1d"},"followers":{"href":null,"total":4.9022656E7},"genres":["classic rock","glam rock","rock"],"href":"https://api.spotify.com/v1/artists/1dfeR4HaWDbWqFHLkxsg1d","id":"1dfeR4HaWDbWqFHLkxsg1d","images":[{"url":"https://i.scdn.co/image/b040846ceba13c3e9c125d68389491094e7f2982","height":806.0,"width":999.0},{"url":"https://i.scdn.co/image/af2b8e57f6d7b5d43a616bd1e27ba552cd8bfd42","height":516.0,"width":640.0},{"url":"https://i.scdn.co/image/c06971e9ff81696699b829484e3be165f4e64368","height":161.0,"width":200.0},{"url":"https://i.scdn.co/image/6dd0ffd270903d1884edf9058c49f58b03db893d","height":52.0,"width":64.0}],"name":"Queen","popularity":84.0,"type":"artist","uri":"spotify:artist:1dfeR4HaWDbWqFHLkxsg1d"}
  1. Notice that some fields’ type are changed to float such as followers.total, popularity

About this issue

  • Original URL
  • State: closed
  • Created 6 months ago
  • Reactions: 4
  • Comments: 24 (17 by maintainers)

Commits related to this issue

Most upvoted comments

One of the workarounds comes to my mind is converting the Integer type to float type to bypass the issue. But in my perspective, I don’t think it’s a great idea because

  1. The SDK shouldn’t silently swallow the bug caused by the Spotify server side, a better solution will be prompting the issue to Spotify and push them to fix the problem
  2. It will introduce a breaking change in this library, which’s definitely unnecessary and avoidable.

I personally prefer to keep escalating and making “noise” to the Spotify developers, the louder noise we could make, the higher probability the Spotify team could be aware of this problem and fix it.

@aome510 @ramsayleung Seems to be fixed ^_^

As expected this is caused by some library that they are using.

I am using spotify_player today and found that at the the artist endpoint works now.

Look like a workaround patch landed to master. @ramsayleung do you have any plans to release a new version?

As I didn’t see any PR related to this I let myself to implement it https://github.com/ramsayleung/rspotify/pull/457.

I tested it with https://github.com/aome510/spotify-player and it worked well.

I don’t think Spotify will give their response anytime soon. I wonder if we have any plans to mitigate this issue @ramsayleung ?

Thanks for your heads-up, I’ve revised the link to the correct one. But it’s odd that a developer replied in the ticket saying what he got with curl was integer data instead of float data.

Unfortunately, this ticket is marked as spam…

I’ve submitted an abuse report.

I am on vacation right now, I will release a new version when I am back 😃

On Sun, Feb 4, 2024 at 1:34 AM Thang Pham @.***> wrote:

Look like a workaround patch landed to master. @ramsayleung https://github.com/ramsayleung do you have any plans to release a new version?

— Reply to this email directly, view it on GitHub https://github.com/ramsayleung/rspotify/issues/452#issuecomment-1925408250, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADMGCSMC32AKD5FDO26MFZ3YRZYLXAVCNFSM6AAAAABBPP63O2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMRVGQYDQMRVGA . You are receiving this because you were mentioned.Message ID: @.***>

This issue is also holding up the development of a project of mine. If it isn’t fixed soon by the spotify developers would rspotify support deserializing all u32 fields with a custom Deserializer a la #[serde(deserialize_with = "as_u32")]? as_u32 would automatically convert float fields into int ones and keep the same default behavior as before. It’s pretty hacky, but it would fix the issue for now/if it arises again (im feeling pretty pessimistic lol). It’d be a less permissive version of serde-this-or-that’s as_u64.

This solution wouldn’t introduce breaking changes in the API as @ramsayleung pointed out, and the fix would continue to work if spotify does get around to fixing the issue. Plus, it would only have the overhead of converting any given f64 to a u32. If there’s any interest in this sort of fix, let me know and I can open up a PR pretty quick.

I’ve sent a message to escalate this issue to the Spotify team via this link: https://support.spotify.com/ca-en/contact-spotify-support/, here is the response from their associate:

I already forward this issue to the team backstage. Also, the tech folks backstage confirm that they’re already ahead of this and currently working for a fix. No need to worry now 😃

Also, our Tech folks are known for their hard work so this will be fixed in no time! Consider this issue resolved.

Yes, I can reproduce your problem now, I’ve submitted a ticket to Spotify to ask for clarity: https://community.spotify.com/t5/Spotify-for-Developers/The-response-type-of-artist-endpoint-is-marked-as-Integer-in/m-p/5800044

Closing since this issue has been resolved by Spotify.