Cannot setup UniFi integration - unknown error occurred

Hello,

I have a USG3 along with a 1st-gen CloudKey, and I’m trying to get the UniFi integration working. I put in my IP address, and I made a specific admin username/password for this integration. Clicking OK then results in a “Unknown error occurred” message at the top. If I check the logs, I see:

    Logger: aiohttp.server
    Source: components/unifi/controller.py:493
    First occurred: 4:45:59 PM (6 occurrences)
    Last logged: 4:55:16 PM
    
    Error handling request
    Traceback (most recent call last):
      File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request
        resp = await self._request_handler(request)
      File "/usr/local/lib/python3.9/site-packages/aiohttp/web_app.py", line 499, in _handle
        resp = await handler(request)
      File "/usr/local/lib/python3.9/site-packages/aiohttp/web_middlewares.py", line 119, in impl
        return await handler(request)
      File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
        return await handler(request)
      File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 77, in forwarded_middleware
        return await handler(request)
      File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 24, in request_context_middleware
        return await handler(request)
      File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 78, in ban_middleware
        return await handler(request)
      File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 144, in auth_middleware
        return await handler(request)
      File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 135, in handle
        result = await result
      File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 155, in post
        return await super().post(request, flow_id)
      File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 63, in wrapper
        result = await method(view, request, *args, **kwargs)
      File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 109, in post
        result = await self._flow_mgr.async_configure(flow_id, data)
      File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 202, in async_configure
        result = await self._async_handle_step(flow, cur_step["step_id"], user_input)
      File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 260, in _async_handle_step
        result: FlowResult = await getattr(flow, method)(user_input)
      File "/usr/src/homeassistant/homeassistant/components/unifi/config_flow.py", line 93, in async_step_user
        controller = await get_controller(
      File "/usr/src/homeassistant/homeassistant/components/unifi/controller.py", line 493, in get_controller
        await controller.login()
      File "/usr/local/lib/python3.9/site-packages/aiounifi/controller.py", line 108, in login
        await self._request("post", url=url, json=auth)
      File "/usr/local/lib/python3.9/site-packages/aiounifi/controller.py", line 274, in _request
        async with self.session.request(
      File "/usr/local/lib/python3.9/site-packages/aiohttp/client.py", line 1117, in __aenter__
        self._resp = await self._coro
      File "/usr/local/lib/python3.9/site-packages/aiohttp/client.py", line 542, in _request
        resp = await req.send(conn)
      File "/usr/local/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 668, in send
        await writer.write_headers(status_line, self.headers)
      File "/usr/local/lib/python3.9/site-packages/aiohttp/http_writer.py", line 118, in write_headers
        buf = _serialize_headers(status_line, headers)
      File "aiohttp/_http_writer.pyx", line 137, in aiohttp._http_writer._serialize_headers
      File "aiohttp/_http_writer.pyx", line 109, in aiohttp._http_writer.to_str
    TypeError: Cannot serialize non-str key None

Am I doing something wrong? Or is something funky with my Controller? Any help is appreciated here. Thanks! Could this be a bug in some component used by HA?

Alternatively, if I can’t get this working - I used to have an auto-discovered integration with my Ubiquiti gateway, which I accidentally deleted - and now I cannot get to show up again, even with HA reboots. It used to show up as “ugw3” in my logs. Any idea how to get this integration again? I really just want to monitor internet traffic…

What do you mean with monitoring traffic? Up and down speed? If so, thr unifi integration doesn’t provide this, you have to use SNMP sensors for this. I have the same router, I documented how I set it up, including enabling of SNMP in the Router here in my repo.

This custom component gives those stats but if you’re struggling to use the built in integration it might not work for you either

Great, that’s exactly what my code will get you. The built-in integration doesn’t provide this measure.