bencevans / sonos-cli

🎶 Command Line Interface for Sonos
https://www.npmjs.com/package/sonos-cli
53 stars 5 forks source link

StatusCodeError: 500 trying to play a spotify song or mp3 stream #20

Open dartheide opened 5 years ago

dartheide commented 5 years ago

Hi,

I installed a new clean debian system to try the sonos-cli. Everything works except playing spotify song or mp3 streams. First I display the current track information and then I try to play that track. It doesn't work. Here is my output.

sonos --zone RINCON_949F3E1BFB3801400:246249917 current-track Title: Sweet Dreams (Are Made of This) - Remastered Album: Sweet Dreams (Are Made Of This) Artist: Eurythmics URI: x-sonos-spotify:spotify%3atrack%3a1TfqLAPs4K3s2rJMoCokcS?sid=9&flags=8224&sn=1

Then sonos --zone RINCON_949F3E1BFB3801400:246249917 stop sonos --zone RINCON_949F3E1BFB3801400:246249917 play x-sonos-spotify:spotify%3atrack%3a5FFowl1Ve4S5OehL6OywSg?sid=9&flags=8224&sn=1

[1] 1498 [2] 1499 hans@debian-jessie-1:/$ (node:1498) UnhandledPromiseRejectionWarning: StatusCodeError: 500 - "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">s:ClientUPnPError<UPnPError xmlns=\"urn:schemas-upnp-org:control-1-0\">804</s:Fault></s:Body></s:Envelope>" at new StatusCodeError (/usr/lib/node_modules/sonos-cli/node_modules/request-promise-core/lib/errors.js:32:15) at Request.plumbing.callback (/usr/lib/node_modules/sonos-cli/node_modules/request-promise-core/lib/plumbing.js:104:33) at Request.RP$callback [as _callback] (/usr/lib/node_modules/sonos-cli/node_modules/request-promise-core/lib/plumbing.js:46:31) at Request.self.callback (/usr/lib/node_modules/sonos-cli/node_modules/request/request.js:185:22) at emitTwo (events.js:126:13) at Request.emit (events.js:214:7) at Request. (/usr/lib/node_modules/sonos-cli/node_modules/request/request.js:1161:10) at emitOne (events.js:116:13) at Request.emit (events.js:211:7) at IncomingMessage. (/usr/lib/node_modules/sonos-cli/node_modules/request/request.js:1083:12) (node:1498) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:1498) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

jeantristan commented 5 years ago

Hello,

I have the same issue here: DEBUG=sonos* sonos-cli list-zones seems to be working:

RINCON_949F3EF2B4D001400:3426505050
  Salle de bains
RINCON_7828CAA1DF8A01400:1378452406
  Thibault
RINCON_B8E9378A15D801400:88
  Séjour
  Cuisine
RINCON_000E5825E4F601400:91
  Chaine Hi
RINCON_000E58E3AD9601400:1047990320
  BRIDGE

But when I try to play a spotify song a zone (single Sonos or several Sonos), I have a 500 error: sonos-cli --zone=RINCON_B8E9378A15D801400:88 play spotify:track:0BgbobvykXxEvxo2HhCuvM

(node:56910) UnhandledPromiseRejectionWarning: StatusCodeError: 500 - "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><s:Fault><faultcode>s:Client</faultcode><faultstring>UPnPError</faultstring><detail><UPnPError xmlns=\"urn:schemas-upnp-org:control-1-0\"><errorCode>804</errorCode></UPnPError></detail></s:Fault></s:Body></s:Envelope>"
    at new StatusCodeError (/usr/local/lib/node_modules/sonos-cli/node_modules/request-promise-core/lib/errors.js:32:15)
    at Request.plumbing.callback (/usr/local/lib/node_modules/sonos-cli/node_modules/request-promise-core/lib/plumbing.js:104:33)
    at Request.RP$callback [as _callback] (/usr/local/lib/node_modules/sonos-cli/node_modules/request-promise-core/lib/plumbing.js:46:31)
    at Request.self.callback (/usr/local/lib/node_modules/sonos-cli/node_modules/request/request.js:185:22)
    at Request.emit (events.js:182:13)
    at Request.<anonymous> (/usr/local/lib/node_modules/sonos-cli/node_modules/request/request.js:1161:10)
    at Request.emit (events.js:182:13)
    at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/sonos-cli/node_modules/request/request.js:1083:12)
    at Object.onceWrapper (events.js:273:13)
    at IncomingMessage.emit (events.js:187:15)
(node:56910) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:56910) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
herennium commented 4 years ago

Hello,

I have the same behaviour as mentioned above - I cannot play any local nor spotify URIs. list-zones and current-track commands are working. Since the problem was mentioned 11 month ago and many new version on sonos-cli and node-sonos came out, I am wondering if there is a general problem or if it is just my environment. Maybe the same problem is hit like in SoCo where they describe general auth issues with spotify etc. I would prefer to work with sonos-cli since its exactly what I'm looking for. Installed it on fresh raspis (1,2,3) with different node versions and actual Sonos Version on Play:1, One and Beam and it wasn't working on all.

Best regards, herennium

haakonstorm commented 4 years ago

Any updates on this?

λ sonos-cli --zone "RINCON_B8E937245D4201400:118" play
(node:24375) UnhandledPromiseRejectionWarning: Error: Request failed with status code 500
    at createError (/usr/local/lib/node_modules/sonos-cli/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/usr/local/lib/node_modules/sonos-cli/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (/usr/local/lib/node_modules/sonos-cli/node_modules/axios/lib/adapters/http.js:236:11)
    at IncomingMessage.emit (events.js:328:22)
    at endReadableNT (_stream_readable.js:1201:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
(node:24375) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:24375) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
flipjs commented 4 years ago

I have the same issue. I have premium EU/UK account. I've seen in node-sonos thread that it could be a region issue? How do you set region in this cli?

bencevans commented 4 years ago

There's no option to set region currently but happy to accept a PR adding something along the lines of --region eu support!

bencevans commented 4 years ago

It'd need to call the setSpotifyRegion(region) function on node-sonos.

herennium commented 4 years ago

Hey,

did a research on "setSpotifyRegion(region)". I have a Spotify EU Premium Account.

1: I did the check on node-sonos: node-sonos/issues/367 -> that worked!

I wrote an examples/test.js

    const Sonos = require('../').Sonos
    const device = new Sonos('192.168.0.136');
    // device.setSpotifyRegion(2311) // 2311 = EU this would work
    console.log(device)
    var spotifyUri = 'spotify:track:1rYeL2lHDreDW5tb4sgPK6'

    device.play(spotifyUri).then(success => {
    console.log('Yeay')
    }).catch(err => { console.log('Error occurred %j', err) })

and started it: node examples/test.js

On console-log I see: spotify: { region: '3079' } When adding device.setSpotifyRegion(2311) the region is set to 2311 and playback will work.

Found out that default region in node-sonos is US in file node-sonos/lib/sonos.js (line 63). this.options.spotify.region = this.options.spotify.region || SpotifyRegion.US

When changing this to EU this.options.spotify.region = this.options.spotify.region || SpotifyRegion.EU I can omit the device.setSpotifyRegion(2311) and it still works. On console-log I see correctly: spotify: { region: '2311' }

2: Now back to sonos-cli:

npm ls -g --depth=1
└─┬ sonos-cli@0.6.1
  ├── minimist@1.2.5
  ├── sonos@1.13.0
  └── underscore@1.10.2

I changed /usr/local/lib/node_modules/sonos-cli/node_modules/sonos/lib/sonos.js line 63 to EU and added debugging console.log(zoneController) as line 74 in /usr/local/lib/node_modules/sonos-cli/bin/sonos in "play" leaf.

When starting sonos --zone=RINCON_8828CA24429E01400:4190638600 play spotify:track:1rYeL2lHDreDW5tb4sgPK6 I get the expected EU console output spotify: { region: '2311' } but it still throws Error: upnp: statusCode 500

Any idea why adapting the region this way didn't help here?

Best regards, herennium

flipjs commented 4 years ago

Same here. Setting the region didnt help. I set it to either EU or US directly in node_modules/sonos.js, I stil get the 500 error. It didn't even get to the sonos function. It throws an exception before setting the region.

This is what I use now:

https://mbc-for-sonos.app/

Its a menubar. It works with or without vpn.