home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.94k stars 30.16k forks source link

UPNP: Error handling request #56937

Closed bouwew closed 3 years ago

bouwew commented 3 years ago

The problem

Adding my TP-LINK AX11000 via discovery fails.

What is version of Home Assistant Core has the issue?

core-2021.10.0b2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Supervised

Integration causing the issue

UPNP

Link to integration documentation on our website

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2021-10-02 10:45:40 ERROR (MainThread) [aiohttp.server] 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 98, 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 136, in handle
result = await result
File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 157, in post
return await super().post(request, flow_id)
File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 62, in wrapper
result = await method(view, request, *args, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 111, in post
result = await self._flow_mgr.async_configure(flow_id, data)
File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 198, 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 256, in _async_handle_step
result: FlowResult = await getattr(flow, method)(user_input)
File "/usr/src/homeassistant/homeassistant/components/upnp/config_flow.py", line 254, in async_step_ssdp_confirm
return await self._async_create_entry_from_discovery(discovery)
File "/usr/src/homeassistant/homeassistant/components/upnp/config_flow.py", line 276, in _async_create_entry_from_discovery
CONFIG_ENTRY_UDN: discovery["_udn"],
KeyError: '_udn'

Additional information

Before this error happens, after a restart this error happens:

2021-10-02 10:41:20 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Archer AX11000 for upnp
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 969, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs) # type: ignore # noqa
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1056, in create_connection
raise exceptions[0]
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1041, in create_connection
sock = await self._connect_sock(
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 955, in _connect_sock
await self.sock_connect(sock, address)
File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 502, in sock_connect
return await fut
File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 537, in _sock_connect_cb
raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('::1', 1900, 0, 0)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/async_upnp_client/aiohttp.py", line 171, in _async_http_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 520, in _request
conn = await self._connector.connect(
File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 535, in connect
proto = await self._create_connection(req, traces, timeout)
File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 892, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 1051, in _create_direct_connection
raise last_exc
File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 1020, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 975, in _wrap_create_connection
raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host ::1:1900 ssl:default [Connect call failed ('::1', 1900, 0, 0)]
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 304, in async_setup
result = await component.async_setup_entry(hass, self) # type: ignore
File "/usr/src/homeassistant/homeassistant/components/upnp/__init__.py", line 125, in async_setup_entry
device = await Device.async_create_device(hass, location)
File "/usr/src/homeassistant/homeassistant/components/upnp/device.py", line 61, in async_create_device
upnp_device = await Device.async_create_upnp_device(hass, ssdp_location)
File "/usr/src/homeassistant/homeassistant/components/upnp/device.py", line 54, in async_create_upnp_device
return await factory.async_create_device(ssdp_location)
File "/usr/local/lib/python3.9/site-packages/async_upnp_client/client_factory.py", line 68, in async_create_device
root_el = await self._async_get(description_url)
File "/usr/local/lib/python3.9/site-packages/async_upnp_client/client_factory.py", line 369, in _async_get
status_code, _, response_body = await self.requester.async_http_request(
File "/usr/local/lib/python3.9/site-packages/async_upnp_client/aiohttp.py", line 139, in async_http_request
return await self._async_http_request(method, url, headers, body)
File "/usr/local/lib/python3.9/site-packages/async_upnp_client/aiohttp.py", line 193, in _async_http_request
raise UpnpConnectionError(str(err)) from err
async_upnp_client.exceptions.UpnpConnectionError: Cannot connect to host ::1:1900 ssl:default [Connect call failed ('::1', 1900, 0, 0)]
probot-home-assistant[bot] commented 3 years ago

Hey there @stevenlooman, @ehendrix23, mind taking a look at this issue as it has been labeled with an integration (upnp) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)


upnp documentation upnp source (message by IssueLinks)

bouwew commented 3 years ago

Some problem as #56938?

bouwew commented 3 years ago

I've noticed other posts, more logging was enabled, the first DEBUG-line shows the discovery-info:

2021-10-03 10:49:48 DEBUG (MainThread) [homeassistant.components.upnp] _async_create_entry_from_discovery: discovery: {'CACHE-CONTROL': 'max-age=120', 'ssdp_st': 'urn:schemas-upnp-org:device:InternetGatewayDevice:1', 'ssdp_usn': 'uuid:e4c797e0-82ce-4f84-b56d-085d9d77c8cd::urn:schemas-upnp-org:device:InternetGatewayDevice:1', 'ssdp_ext': '', 'ssdp_server': 'TP-LINK/TP-LINK UPnP/1.1 MiniUPnPd/1.8', 'OPT': '"http://schemas.upnp.org/upnp/1/0/"; ns=01', '01-NLS': '1', 'BOOTID.UPNP.ORG': '1', 'CONFIGID.UPNP.ORG': '1337', '_location_original': 'http://[::1]:1900/rootDesc.xml', 'ssdp_location': 'http://[::1]:1900/rootDesc.xml', '_timestamp': datetime.datetime(2021, 10, 3, 10, 49, 7, 275160), '_host': '192.168.123.321', '_port': 1900, 'ssdp_udn': 'uuid:e4c797e0-82ce-4f84-b56d-085d9d77c8cd', 'deviceType': 'urn:schemas-upnp-org:device:InternetGatewayDevice:1', 'friendlyName': 'Archer AX11000', 'manufacturer': 'TP-Link', 'manufacturerURL': 'http://www.tp-link.com/', 'modelDescription': 'Archer AX11000', 'modelName': 'Archer AX11000', 'modelNumber': '1.0', 'modelURL': 'http://www.tp-link.com/', 'serialNumber': '00000000', 'UDN': 'uuid:e4c797e0-82ce-4f84-b56d-085d9d77c8cd', 'serviceList': {'service': {'serviceType': 'urn:schemas-upnp-org:service:Layer3Forwarding:1', 'serviceId': 'urn:upnp-org:serviceId:Layer3Forwarding1', 'controlURL': '/ctl/L3F', 'eventSubURL': '/evt/L3F', 'SCPDURL': '/L3F.xml'}}, 'deviceList': {'device': {'deviceType': 'urn:schemas-upnp-org:device:WANDevice:1', 'friendlyName': 'WANDevice', 'manufacturer': 'MiniUPnP', 'manufacturerURL': 'http://miniupnp.free.fr/', 'modelDescription': 'WAN Device', 'modelName': 'WAN Device', 'modelNumber': '20210511', 'modelURL': 'http://miniupnp.free.fr/', 'serialNumber': '00000000', 'UDN': 'uuid:e4c797e0-82ce-4f84-b56d-085d9d77c8cd', 'UPC': '000000000000', 'serviceList': {'service': {'serviceType': 'urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1', 'serviceId': 'urn:upnp-org:serviceId:WANCommonIFC1', 'controlURL': '/ctl/CmnIfCfg', 'eventSubURL': '/evt/CmnIfCfg', 'SCPDURL': '/WANCfg.xml'}}, 'deviceList': {'device': {'deviceType': 'urn:schemas-upnp-org:device:WANConnectionDevice:1', 'friendlyName': 'WANConnectionDevice', 'manufacturer': 'MiniUPnP', 'manufacturerURL': 'http://miniupnp.free.fr/', 'modelDescription': 'MiniUPnP daemon', 'modelName': 'MiniUPnPd', 'modelNumber': '20210511', 'modelURL': 'http://miniupnp.free.fr/', 'serialNumber': '00000000', 'UDN': 'uuid:e4c797e0-82ce-4f84-b56d-085d9d77c8cd', 'UPC': '000000000000', 'serviceList': {'service': {'serviceType': 'urn:schemas-upnp-org:service:WANIPConnection:1', 'serviceId': 'urn:upnp-org:serviceId:WANIPConn1', 'controlURL': '/ctl/IPConn', 'eventSubURL': '/evt/IPConn', 'SCPDURL': '/WANIPCn.xml'}}}}}}, 'presentationURL': 'http://192.168.123.321/'}
2021-10-03 10:49:48 ERROR (MainThread) [aiohttp.server] 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 98, 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 136, in handle
result = await result
File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 157, in post
return await super().post(request, flow_id)
File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 62, in wrapper
result = await method(view, request, *args, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 111, in post
result = await self._flow_mgr.async_configure(flow_id, data)
File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 198, 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 256, in _async_handle_step
result: FlowResult = await getattr(flow, method)(user_input)
File "/usr/src/homeassistant/homeassistant/components/upnp/config_flow.py", line 254, in async_step_ssdp_confirm
return await self._async_create_entry_from_discovery(discovery)
File "/usr/src/homeassistant/homeassistant/components/upnp/config_flow.py", line 276, in _async_create_entry_from_discovery
CONFIG_ENTRY_UDN: discovery["_udn"],
KeyError: '_udn'
bouwew commented 3 years ago

Let me know if I need to provide more DEBUG-info.

StevenLooman commented 3 years ago

Thank you for the bug report @bouwew.

Interesting, the key _udn should have been set, but somehow wasn't. I'm going to fix a few tickets today, I'll include this one.

bouwew commented 3 years ago

@StevenLooman Great! Let me know if I can do some testing.

StevenLooman commented 3 years ago

@bouwew, a fix for this will be included in the upcoming release.

bouwew commented 3 years ago

@StevenLooman I've implemented your fix manually, its working now but I don't see any of the DERIVED_SENSORS?