Issues with Node-Red addon - Call-service API error

Hi all,

Got a problem with my Node-Red installation within my hassio. This has been working fine before, but after a backp/restore of my hassio instance is not working with my node-red.

Have reinstalled and remove the node-red folder but still no go, could it be some old tokens or something?

Running hass.io from a Synology NAS

Home Assistant: 0.98.5
Hass.io supervisor: 188

Errors from my hassio log:

19-09-16 18:52:11 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/usr/src/hassio/hassio/api/security.py", line 111, in token_validation
    return await handler(request)
  File "/usr/src/hassio/hassio/api/proxy.py", line 203, in websocket
    client = await self._websocket_client()
  File "/usr/src/hassio/hassio/api/proxy.py", line 114, in _websocket_client
    url, heartbeat=30, verify_ssl=False
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 731, in _ws_connect
    headers=resp.headers)
aiohttp.client_exceptions.WSServerHandshakeError: 403, message='Invalid response status'
19-09-16 18:52:11 ERROR (MainThread) [aiohttp.server] Unhandled exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 447, in start
    await resp.prepare(request)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_response.py", line 353, in prepare
    return await self._start(request)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_response.py", line 667, in _start
    return await super()._start(request)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_response.py", line 410, in _start
    await writer.write_headers(status_line, headers)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/http_writer.py", line 112, in write_headers
    self._write(buf)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/http_writer.py", line 67, in _write
    raise ConnectionResetError('Cannot write to closing transport')
ConnectionResetError: Cannot write to closing transport
19-09-16 18:52:16 INFO (MainThread) [hassio.api.proxy] Home Assistant WebSocket API request initialize
19-09-16 18:52:16 INFO (MainThread) [hassio.api.proxy] WebSocket access from a0d7b954_nodered
19-09-16 18:52:16 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/usr/src/hassio/hassio/api/security.py", line 111, in token_validation
    return await handler(request)
  File "/usr/src/hassio/hassio/api/proxy.py", line 203, in websocket
    client = await self._websocket_client()
  File "/usr/src/hassio/hassio/api/proxy.py", line 114, in _websocket_client
    url, heartbeat=30, verify_ssl=False
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 731, in _ws_connect
    headers=resp.headers)
aiohttp.client_exceptions.WSServerHandshakeError: 403, message='Invalid response status'
19-09-16 18:52:16 ERROR (MainThread) [aiohttp.server] Unhandled exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 447, in start
    await resp.prepare(request)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_response.py", line 353, in prepare
    return await self._start(request)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_response.py", line 667, in _start
    return await super()._start(request)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_response.py", line 410, in _start
    await writer.write_headers(status_line, headers)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/http_writer.py", line 112, in write_headers
    self._write(buf)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/http_writer.py", line 67, in _write
    raise ConnectionResetError('Cannot write to closing transport')
ConnectionResetError: Cannot write to closing transport
19-09-16 18:52:21 INFO (MainThread) [hassio.api.proxy] Home Assistant WebSocket API request initialize
19-09-16 18:52:21 INFO (MainThread) [hassio.api.proxy] WebSocket access from a0d7b954_nodered
19-09-16 18:52:41 ERROR (MainThread) [asyncio] Task exception was never retrieved
future: <Task finished coro=<WebSocketWriter.ping() done, defined at /usr/local/lib/python3.7/site-packages/aiohttp/http_websocket.py:628> exception=RuntimeError('unable to perform operation on <TCPTransport closed=True reading=False 0x7ff4f6864d60>; the handler is closed')>
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/http_websocket.py", line 632, in ping
    await self._send_frame(message, WSMsgType.PING)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/http_websocket.py", line 614, in _send_frame
    self.transport.write(header + message)
  File "uvloop/handles/stream.pyx", line 671, in uvloop.loop.UVStream.write
  File "uvloop/handles/handle.pyx", line 159, in uvloop.loop.UVHandle._ensure_alive
RuntimeError: unable to perform operation on <TCPTransport closed=True reading=False 0x7ff4f6864d60>; the handler is closed
19-09-16 18:52:46 ERROR (MainThread) [asyncio] Task exception was never retrieved
future: <Task finished coro=<WebSocketWriter.ping() done, defined at /usr/local/lib/python3.7/site-packages/aiohttp/http_websocket.py:628> exception=RuntimeError('unable to perform operation on <TCPTransport closed=True reading=False 0x7ff4f67eff80>; the handler is closed')>
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/http_websocket.py", line 632, in ping
    await self._send_frame(message, WSMsgType.PING)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/http_websocket.py", line 614, in _send_frame
    self.transport.write(header + message)
  File "uvloop/handles/stream.pyx", line 671, in uvloop.loop.UVStream.write
  File "uvloop/handles/handle.pyx", line 159, in uvloop.loop.UVHandle._ensure_alive

Log from node-red addon:

16 Sep 20:53:06 - [info] [server:Home Assistant] WebSocket Closed http://hassio/homeassistant
16 Sep 20:53:06 - [error] [api-call-service:Lys] Call-service API error.
16 Sep 20:53:11 - [info] [server:Home Assistant] WebSocket Connected to http://hassio/homeassistant
16 Sep 20:53:11 - [info] [server:Home Assistant] WebSocket Closed http://hassio/homeassistant
16 Sep 20:53:16 - [info] [server:Home Assistant] WebSocket Connected to http://hassio/homeassistant
16 Sep 20:53:16 - [info] [server:Home Assistant] WebSocket Closed http://hassio/homeassistant
16 Sep 20:53:21 - [info] [server:Home Assistant] WebSocket Connected to http://hassio/homeassistant
RuntimeError: unable to perform operation on <TCPTransport closed=True reading=False 0x7ff4f67eff80>; the handler is closed

Just ran into this issue on Proxmox + Ubuntu VM + Hassio and wanted to hopefully save someone from a headache. Below is what eventually worked for me.

  1. Auth errors eventually resulted in an ip ban (172.30.32.2) in ip_bans.yaml. Removed the file / entry and still had issue (but one step closer)
  2. Did a full removal of addon by uninstalling through hassio + deleting node-red folder (this will return everything to a blank slate)
  3. Rebooted my entire host instead of just homeassistant
  4. Installed nodered again and the api issues were gone