Skip to content
This repository has been archived by the owner on Jul 4, 2020. It is now read-only.

https://api.spotify.com/v1/me/player/next error #859

Closed
imminna opened this issue May 2, 2018 · 11 comments
Closed

https://api.spotify.com/v1/me/player/next error #859

imminna opened this issue May 2, 2018 · 11 comments

Comments

@imminna
Copy link

imminna commented May 2, 2018

Issue found on May 2rd 2018.

Endpoint(s):

Actual behaviour:

411 Server Error (consistently)
However I can't find the information about this error

@onemanbucket
Copy link

Hi!

Try setting Content-Length: 0 as a header

@imminna
Copy link
Author

imminna commented May 3, 2018

Thanks, It's solved.
I did'nt set Content-Length: 0 as a header while using this API a month ago , however it works.
It seems this API make the revision.
could you please list the revision note while Spotify Web-API make the change ? THANKS!!

@michaelherger
Copy link

I do indeed see "411 Length Required". Please fix this issue or the documentation. Thank!

Thanks @onemanbucket - I'll give that a try. I'm wondering whether they expect length to be the seconds played on the previous song or similar. It's something I've seen for other streaming services' APIs.

@michaelherger
Copy link

michaelherger commented May 3, 2018

BTW: I'm getting the same for other player endpoints, eg. /me/player/pause, /me/player/volume

@onemanbucket
Copy link

@michaelherger the Content-Length header is part of the HTTP spec and its value should be the length of the request body (in this case zero bytes).

@JoaaoVerona
Copy link

JoaaoVerona commented May 3, 2018

+1. I'm also getting it for /me/player/seek. What's more strange is, the content returned is a Google-like HTML error page, saying that a Content-Length header is required for POST requests, but... this endpoint is PUT. 🤔

Content-Length was never required to be set before, so either this is a temporary error, or this should be stated in the Web API documentation, as @michaelherger said.

Update: I've set a Content-Length: 0 header, but this error is still happening. So... I think it's a bug on the Spotify end? Maybe their end is making a request to some Google-related service, and there's no Content-Length header set on that request...

Update2: Here's a stack trace example for the /me/player/pause endpoint.

com.github.bloodshura.x.http.service.ServiceException$NotOkResponse: HTTP response code 411 from URL "https://api.spotify.com/v1/me/player/pause":
    Body:
        <!DOCTYPE html>
        <html lang=en>
        <meta charset=utf-8>
        <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
        <title>Error 411 (Length Required)!!1</title>
        <style>
        *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
        </style>
        <a href=//www.google.com/><span id=logo aria-label=Google></span></a>
        <p><b>411.</b> <ins>That’s an error.</ins>
        <p>POST requests require a <code>Content-length</code> header.  <ins>That’s all we know.</ins>

    Request headers:
        Accept: application/json
        Authorization: <REMOVED>
        Content-Length: 0

    Response headers:
        Referrer-Policy: no-referrer
        Content-Length: 1564
        Date: Thu, 03 May 2018 06:42:39 GMT
        Content-Type: text/html; charset=UTF-8
at com.github.bloodshura.skiley.SpotifyEndpoint$Playback.playbackExecute(Endpoint.kt:804)
at com.github.bloodshura.skiley.SpotifyEndpoint$Playback.pause(Endpoint.kt:733)
...

@michaelherger
Copy link

Setting it to 0 did work for me, too.

To be fair these calls are still clearly labeled beta, with a warning that they could change any time. See https://beta.developer.spotify.com/documentation/web-api/reference/player/

@onemanbucket
Copy link

This is caused by an infrastructure change in the webapi load balancer, it's now behind a google https load balancer, which will reject illegal requests according to these rules: https://cloud.google.com/compute/docs/load-balancing/http/#illegal_request_handling

@BloodShura your request looks correct, can you provide a reproducable example and i'll investigate

@michaelherger
Copy link

@JoaaoVerona
Copy link

JoaaoVerona commented May 3, 2018

@onemanbucket I managed to fix it!

If anyone else is also setting a Content-Length: 0 header and is still experiencing this issue...

Behind the scenes, I'm using the Java's HTTP API (java.net.HttpURLConnection). By default, using connection.setRequestProperty("Content-Length", 0) will be ignored, because the Content-Length header is set automatically when you write data onto the connection's output stream.

The problem is: since some of these endpoints (like /me/player/seek) do not require anything to be sent in the body of the request (only in the query parameters), I, of course, wasn't writing anything to the connection's output stream, which caused the Java's API to not set the Content-Length header.

Then what I did was, convert the request to a "with-body" request (which will vary on which higher-level API you're using afterall), but without writing anything to the connection's output stream. This way, the output stream is opened, nothing is written, then the Java's API correctly sets a Content-Length: 0 header.

@onemanbucket
Copy link

that's great!

looks like we can close this ticket

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants