core: Unifi : No longer able to control Block/Unblock of network clients with latest HA Core.

The problem

HA no longer able to Block/Unblock network clients. Unifi configuration unchanged, controller version has not changed.

Environment

  • RUnning on ver : Home Assistant 0.107.1
  • Last working Home Assistant release (if known): Not Known
  • Operating environment (Hass.io/Docker/Windows/etc.): Win10 hosting HASSIO VM.
  • Integration causing this issue: Unifi COntroller
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/unifi

Problem-relevant configuration.yaml

Traceback/Error logs

Additional information

Integration Removed and Readded. No effect.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 61 (23 by maintainers)

Most upvoted comments

I’ve been able to replicate the issue.

The session is expiring and being logged out AFAICT.

2020-07-02 01:50:14 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.139803720424592] Call https://unifi:443/proxy/network/api/s/default/cmd/stamgr received 401 Unauthorized
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 130, in handle_call_service
    connection.context(msg),
  File "/usr/src/homeassistant/homeassistant/core.py", line 1269, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1304, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 209, in handle_service
    self._platforms.values(), func, call, required_features
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 454, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 595, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 485, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/unifi/switch.py", line 278, in async_turn_off
    await self.controller.api.clients.async_block(self.client.mac)
  File "/usr/local/lib/python3.7/site-packages/aiounifi/clients.py", line 22, in async_block
    await self._request("post", URL_CLIENT_STATE_MANAGER, json=data)
  File "/usr/local/lib/python3.7/site-packages/aiounifi/controller.py", line 213, in request
    raise LoginRequired(f"Call {url} received 401 Unauthorized")
aiounifi.errors.LoginRequired: Call https://unifi:443/proxy/network/api/s/default/cmd/stamgr received 401 Unauthorized

I tried to figure out what the root cause for “404 unauthorized” messages and I think here is the reason. Right after disable/enable the switch for block/unblock a device the following message got logged on UDM. I googled the error and it seems to be a problem with expired session cookies. Maybe it helps you or others to get the issue fixed somehow.

The path to the log file is: /mnt/data/unifi-os/unifi-core/logs/http.log

2020-06-25T12:28:11.339Z - error: [https] 8ms 404 POST /proxy/network/api/s/default/cmd/stamgr 2020-06-25T12:28:11.339Z - error: ForbiddenError: Invalid CSRF Token at Object.throw (/usr/share/unifi-core/app/webpack:/node_modules/koa/lib/context.js:97:11) at fn (/usr/share/unifi-core/app/webpack:/src/middleware/http/koa/csrf.js:21:34) at fn (/usr/share/unifi-core/app/webpack:/node_modules/koa-compose/index.js:42:32) at upstream (/usr/share/unifi-core/app/webpack:/node_modules/koa-compose/index.js:42:32) at fn (/usr/share/unifi-core/app/webpack:/node_modules/koa-mount/index.js:52:32) at upstream (/usr/share/unifi-core/app/webpack:/node_modules/koa-compose/index.js:42:32) at fn (/usr/share/unifi-core/app/webpack:/node_modules/koa-mount/index.js:52:32) at upstream (/usr/share/unifi-core/app/webpack:/node_modules/koa-compose/index.js:42:32) at fn (/usr/share/unifi-core/app/webpack:/node_modules/koa-mount/index.js:52:32) at dispatch (/usr/share/unifi-core/app/webpack:/node_modules/koa-compose/index.js:42:32) at proxyMiddleware (/usr/share/unifi-core/app/webpack:/node_modules/koa-compose/index.js:34:12) at fn (/usr/share/unifi-core/app/webpack:/src/middleware/http/appProxy/ui.js:58:12) at next (/usr/share/unifi-core/app/webpack:/node_modules/koa-compose/index.js:42:32) at redirectCheck (/usr/share/unifi-core/app/webpack:/src/middleware/http/koa/redirectCheck.js:20:79) at fn (/usr/share/unifi-core/app/webpack:/src/middleware/http/index.js:111:14) at i (/usr/share/unifi-core/app/webpack:/node_modules/koa-compose/index.js:42:32)