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:
- Run
curl --request GET \
--url https://api.spotify.com/v1/artists/1dfeR4HaWDbWqFHLkxsg1d \
--header 'Authorization: Bearer $TOKEN'
- 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"}
- 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
- Temp fix for https://github.com/ramsayleung/rspotify/issues/452 — committed to Marekkon5/rspotify by Marekkon5 5 months ago
- Workaround for Spotify API bug Due to Spotify API returning floats instead of uints for some fields of the Artist it cannot be parsed. This commit adds deserializing float values into u32 as a workar... — committed to m-torhan/rspotify by m-torhan 5 months ago
- Workaround for Spotify API bug Due to Spotify API returning floats instead of uints for some fields of the Artist it cannot be parsed. This commit adds deserializing float values into u32 as a workar... — committed to m-torhan/rspotify by m-torhan 5 months ago
- Workaround for Spotify API bug Due to Spotify API returning floats instead of uints for some fields of the Artist it cannot be parsed. This commit adds deserializing float values into u32 as a workar... — committed to m-torhan/rspotify by m-torhan 5 months ago
- Patch spotify API bugs (#386) Resolves #330 Resolves #383 Resolves #384 Related upstream issues: - https://github.com/ramsayleung/rspotify/issues/452 - https://github.com/ramsayleung/rspoti... — committed to aome510/spotify-player by aome510 4 months ago
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
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 theartist
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:
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 customDeserializer
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 ofserde-this-or-that
’sas_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 au32
. 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:
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.