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

UnhandledPromiseRejectionWarning Error 405 Method Not Allowed #5

Open
pierrephi opened this issue Jun 10, 2021 · 5 comments
Open

UnhandledPromiseRejectionWarning Error 405 Method Not Allowed #5

pierrephi opened this issue Jun 10, 2021 · 5 comments

Comments

@pierrephi
Copy link

pierrephi commented Jun 10, 2021

Hello

I have been unable to make this module work and I think I have narrowed it down to a Sonos Boost in my system
Every time the boost is plugged in I get the following errors and the module displays nothing

0|mm  | [10.06.2021 18:56.52.463] [ERROR]
0|mm  | (node:31409) UnhandledPromiseRejectionWarning: Error: upnp: Request failed with status code 405///<HTML><HEAD><TITLE>Error 405</TITLE></HEAD><BODY><H1>Error 405</H1><P>Method Not Allowed</P></BODY></HTML>
0|mm  |     at /home/pi/MagicMirror/modules/MMM-Sonos/node_modules/sonos/lib/services/Service.js:90:25
0|mm  |     at runMicrotasks (<anonymous>)
0|mm  |     at processTicksAndRejections (internal/process/task_queues.js:97:5)
0|mm  | [10.06.2021 18:56.52.464] [ERROR] (node:31409) 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: 9
)

My take is that an unrecognised command is sent to the boost and the error is not properly handled/ignored
This is the boost device object in my system, nothing seems to distinguish it from the speaker devices

Sonos {
  host: '192.168.1.162',
  port: 1400,
  options: {
    endpoints: {
      transport: '/MediaRenderer/AVTransport/Control',
      rendering: '/MediaRenderer/RenderingControl/Control',
      device: '/DeviceProperties/Control'
    },
    spotify: { region: '3079' }
  },
  _events: [Object: null prototype] {
    newListener: [AsyncFunction: implicitListen]
  },
  _eventsCount: 1
}

I will try to trace it down to the actual error but documenting here what I have found thus far

@pierrephi
Copy link
Author

Error captured in debug mode:

[10.06.2021 22:58.30.533] [ERROR] Whoops! There was an uncaught exception...
[10.06.2021 22:58.30.537] [ERROR] Error: Request failed with status code 405
    at createError (/Users/pdicostanzo/Dropbox/Development/MagicMirror/modules/MMM-Sonos/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/Users/pdicostanzo/Dropbox/Development/MagicMirror/modules/MMM-Sonos/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (/Users/pdicostanzo/Dropbox/Development/MagicMirror/modules/MMM-Sonos/node_modules/axios/lib/adapters/http.js:237:11)
    at IncomingMessage.emit (node:events:391:22)
    at endReadableNT (node:internal/streams/readable:1307:12)
    at processTicksAndRejections (node:internal/process/task_queues:81:21) {
  config: {
    url: 'http://192.168.1.162:1400/MediaRenderer/AVTransport/Control',
    method: 'post',
    data: '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetTransportInfo xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID></u:GetTransportInfo></s:Body></s:Envelope>',
    headers: {
      Accept: 'application/json, text/plain, */*',
      'Content-Type': 'text/xml; charset=utf8',
      SOAPAction: '"urn:schemas-upnp-org:service:AVTransport:1#GetTransportInfo"',
      'User-Agent': 'axios/0.19.0',
      'Content-Length': 274
    },
    transformRequest: [ [Function: transformRequest] ],
    transformResponse: [ [Function: transformResponse] ],
    timeout: 0,
    adapter: [Function: httpAdapter],
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    validateStatus: [Function: validateStatus]
  },
  request: <ref *1> ClientRequest {
    _events: [Object: null prototype] {
      abort: [Function (anonymous)],
      aborted: [Function (anonymous)],
      error: [Function (anonymous)],
      socket: [Function (anonymous)],
      timeout: [Function (anonymous)],
      prefinish: [Function: requestOnPrefinish]
    },
    _eventsCount: 6,
    _maxListeners: undefined,
    outputData: [],
    outputSize: 0,
    writable: true,
    destroyed: false,
    _last: true,
    chunkedEncoding: false,
    shouldKeepAlive: false,
    _defaultKeepAlive: true,
    useChunkedEncodingByDefault: true,
    sendDate: false,
    _removedConnection: false,
    _removedContLen: false,
    _removedTE: false,
    _contentLength: null,
    _hasBody: true,
    _trailer: '',
    finished: true,
    _headerSent: true,
    _closed: false,
    socket: Socket {
      connecting: false,
      _hadError: false,
      _parent: null,
      _host: null,
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 8,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: false,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: null,
      _server: null,
      parser: null,
      _httpMessage: [Circular *1],
      write: [Function: writeAfterFIN],
      [Symbol(async_id_symbol)]: 1118,
      [Symbol(kHandle)]: null,
      [Symbol(kSetNoDelay)]: false,
      [Symbol(lastWriteQueueSize)]: 0,
      [Symbol(timeout)]: null,
      [Symbol(kBuffer)]: null,
      [Symbol(kBufferCb)]: null,
      [Symbol(kBufferGen)]: null,
      [Symbol(kCapture)]: false,
      [Symbol(kBytesRead)]: 252,
      [Symbol(kBytesWritten)]: 574,
      [Symbol(RequestTimeout)]: undefined
    },
    _header: 'POST /MediaRenderer/AVTransport/Control HTTP/1.1\r\n' +
      'Accept: application/json, text/plain, */*\r\n' +
      'Content-Type: text/xml; charset=utf8\r\n' +
      'SOAPAction: "urn:schemas-upnp-org:service:AVTransport:1#GetTransportInfo"\r\n' +
      'User-Agent: axios/0.19.0\r\n' +
      'Content-Length: 274\r\n' +
      'Host: 192.168.1.162:1400\r\n' +
      'Connection: close\r\n' +
      '\r\n',
    _keepAliveTimeout: 0,
    _onPendingData: {},
    agent: Agent {
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      defaultPort: 80,
      protocol: 'http:',
      options: [Object],
      requests: {},
      sockets: [Object],
      freeSockets: {},
      keepAliveMsecs: 1000,
      keepAlive: false,
      maxSockets: Infinity,
      maxFreeSockets: 256,
      scheduling: 'lifo',
      maxTotalSockets: Infinity,
      totalSocketCount: 48,
      [Symbol(kCapture)]: false
    },
    socketPath: undefined,
    method: 'POST',
    maxHeaderSize: undefined,
    insecureHTTPParser: undefined,
    path: '/MediaRenderer/AVTransport/Control',
    _ended: true,
    res: IncomingMessage {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 3,
      _maxListeners: undefined,
      socket: [Socket],
      httpVersionMajor: 1,
      httpVersionMinor: 1,
      httpVersion: '1.1',
      complete: true,
      rawHeaders: [Array],
      rawTrailers: [],
      aborted: false,
      upgrade: false,
      url: '',
      method: null,
      statusCode: 405,
      statusMessage: 'Method Not Allowed',
      client: [Socket],
      _consuming: true,
      _dumped: false,
      req: [Circular *1],
      responseUrl: 'http://192.168.1.162:1400/MediaRenderer/AVTransport/Control',
      redirects: [],
      [Symbol(kCapture)]: false,
      [Symbol(kHeaders)]: [Object],
      [Symbol(kHeadersCount)]: 8,
      [Symbol(kTrailers)]: null,
      [Symbol(kTrailersCount)]: 0,
      [Symbol(RequestTimeout)]: undefined
    },
    aborted: false,
    timeoutCb: null,
    upgradeOrConnect: false,
    parser: null,
    maxHeadersCount: null,
    reusedSocket: false,
    host: '192.168.1.162',
    protocol: 'http:',
    _redirectable: Writable {
      _writableState: [WritableState],
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      _options: [Object],
      _redirectCount: 0,
      _redirects: [],
      _requestBodyLength: 274,
      _requestBodyBuffers: [],
      _onNativeResponse: [Function (anonymous)],
      _currentRequest: [Circular *1],
      _currentUrl: 'http://192.168.1.162:1400/MediaRenderer/AVTransport/Control',
      [Symbol(kCapture)]: false
    },
    [Symbol(kCapture)]: false,
    [Symbol(kNeedDrain)]: false,
    [Symbol(corked)]: 0,
    [Symbol(kOutHeaders)]: [Object: null prototype] {
      accept: [Array],
      'content-type': [Array],
      soapaction: [Array],
      'user-agent': [Array],
      'content-length': [Array],
      host: [Array]
    }
  },
  response: {
    status: 405,
    statusText: 'Method Not Allowed',
    headers: {
      allow: 'GET, HEAD',
      'content-type': 'text/html',
      server: 'Linux UPnP/1.0 Sonos/63.2-89260 (BR200)',
      connection: 'close'
    },
    config: {
      url: 'http://192.168.1.162:1400/MediaRenderer/AVTransport/Control',
      method: 'post',
      data: '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetTransportInfo xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID></u:GetTransportInfo></s:Body></s:Envelope>',
      headers: [Object],
      transformRequest: [Array],
      transformResponse: [Array],
      timeout: 0,
      adapter: [Function: httpAdapter],
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      validateStatus: [Function: validateStatus]
    },
    request: <ref *1> ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 6,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: false,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: true,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      _contentLength: null,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      _closed: false,
      socket: [Socket],
      _header: 'POST /MediaRenderer/AVTransport/Control HTTP/1.1\r\n' +
        'Accept: application/json, text/plain, */*\r\n' +
        'Content-Type: text/xml; charset=utf8\r\n' +
        'SOAPAction: "urn:schemas-upnp-org:service:AVTransport:1#GetTransportInfo"\r\n' +
        'User-Agent: axios/0.19.0\r\n' +
        'Content-Length: 274\r\n' +
        'Host: 192.168.1.162:1400\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: {},
      agent: [Agent],
      socketPath: undefined,
      method: 'POST',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      path: '/MediaRenderer/AVTransport/Control',
      _ended: true,
      res: [IncomingMessage],
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: '192.168.1.162',
      protocol: 'http:',
      _redirectable: [Writable],
      [Symbol(kCapture)]: false,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype]
    },
    data: '<HTML><HEAD><TITLE>Error 405</TITLE></HEAD><BODY><H1>Error 405</H1><P>Method Not Allowed</P></BODY></HTML>'
  },
  isAxiosError: true,
  toJSON: [Function (anonymous)]
}

@pierrephi
Copy link
Author

Tracking issue in bencevans/node-sonos/issues/515

@goldyfruit
Copy link

@pierrephi Have you been able to sort this out?

@goldyfruit
Copy link

goldyfruit commented Mar 11, 2022

My issue seems to be a bit different than yours.

  {
    Coordinator: 'XXX',
    ID: 'XXX',
    ZoneGroupMember: [ [Object] ],
    Name: 'Dining Room',
    host: '192.168.1.30',
    port: 1400,
    CoordinatorDevice: [Function (anonymous)]
  },
  {
    Coordinator: 'XXX',
    ID: 'XXX',
    ZoneGroupMember: [ [Object] ],
    Name: 'Living Room',
    host: '192.168.1.71',
    port: 1400,
    CoordinatorDevice: [Function (anonymous)]
  },
  {
    Coordinator: 'XXX',
    ID: 'XXX',
    ZoneGroupMember: [ [Object] ],
    Name: 'Library',
    host: '192.168.1.222',
    port: 1400,
    CoordinatorDevice: [Function (anonymous)]
  },
  {
    Coordinator: 'XXX',
    ID: 'XXX',
    ZoneGroupMember: [ [Object] ],
    Name: 'Office',
    host: '192.168.1.112',
    port: 1400,
    CoordinatorDevice: [Function (anonymous)]
  },
  {
    Coordinator: 'XXX',
    ID: 'XXX',
    ZoneGroupMember: [ [Object] ],
    Name: 'TV Room',
    host: '192.168.1.25',
    port: 1400,
    CoordinatorDevice: [Function (anonymous)]
  }
]
[11.03.2022 11:51.58.356] [LOG]   Sonos {
  host: '192.168.1.30',
  port: 1400,
  options: {
    endpoints: {
      transport: '/MediaRenderer/AVTransport/Control',
      rendering: '/MediaRenderer/RenderingControl/Control',
      device: '/DeviceProperties/Control'
    },
    spotify: { region: '3079' }
  },
  _events: [Object: null prototype] {
    newListener: [AsyncFunction: implicitListen]
  },
  _eventsCount: 1
}
[11.03.2022 11:55.19.086] [ERROR] Failed to get groups: sonos.getCurrentUriMetadata is not a function. Retrying in 30 seconds ...

@goldyfruit
Copy link

goldyfruit commented Mar 11, 2022

@pierrephi I applied your commit pierrephi@a21556e, still get the 405 but it works for the others.

[11.03.2022 13:26.54.405] [LOG]   Error: upnp: Request failed with status code 405///<HTML><HEAD><TITLE>Error 405</TITLE></HEAD><BODY><H1>Error 405</H1><P>Method Not Allowed</P></BODY></HTML>
    at /opt/mm/modules/MMM-Sonos/node_modules/sonos/lib/services/Service.js:90:25
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
[11.03.2022 13:26.54.426] [LOG]   Registering listeners for group "Office + 3" (host "192.168.1.112")
[11.03.2022 13:26.54.607] [LOG]   [Group Office + 3 - 192.168.1.112] Track changed to "All The Things (Your Man Won't Do)" by "Joe"
[11.03.2022 13:26.54.616] [LOG]   [Group Office + 3 - 192.168.1.112] Play state change to "playing"
[11.03.2022 13:26.55.132] [LOG]   [Group Office + 3 - 192.168.1.112] Volume changed to "10"
[11.03.2022 13:26.55.137] [LOG]   [Group Office + 3 - 192.168.1.112] Group is unmuted

It would be great if you could push a PR on this repository, I'm sure we are not the only ones facing this issue.

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

No branches or pull requests

2 participants