You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If host computer is connected to open wifi network, network.py script fails, /network/info page returns http code 500 and supervisor control panel cannot load
What is the used version of the Supervisor?
supervisor-2021.03.9
What type of installation are you running?
Home Assistant Supervised
Which operating system are you running on?
Other (e.g., Raspbian/Raspberry Pi OS/Fedora)
What is the version of your installed operating system?
Ubuntu 20.10 aarch64 for Raspberry PI 4
What version of Home Assistant Core is installed?
core-2021.3.4
Steps to reproduce the issue
Connect to open wifi network
Try to open supervisor panel
Anything in the Supervisor logs that might be useful for us?
Core logs:
2021-03-08 21:35:17 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 314, in data_received
messages, upgraded, tail = self._request_parser.feed_data(data)
File "aiohttp/_http_parser.pyx", line 546, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'invalid HTTP method'"
2021-03-08 22:02:33 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 314, in data_received
messages, upgraded, tail = self._request_parser.feed_data(data)
File "aiohttp/_http_parser.pyx", line 546, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'invalid HTTP method'"
2021-03-08 22:59:03 ERROR (MainThread) [homeassistant.components.hassio.handler] /network/info return code 500
2021-03-08 22:59:03 ERROR (MainThread) [homeassistant.components.hassio] Failed to to call /network/info -
2021-03-08 23:01:51 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 314, in data_received
messages, upgraded, tail = self._request_parser.feed_data(data)
File "aiohttp/_http_parser.pyx", line 546, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'invalid HTTP method'"
2021-03-08 23:21:10 ERROR (MainThread) [homeassistant.components.hassio.handler] /network/info return code 500
2021-03-08 23:21:10 ERROR (MainThread) [homeassistant.components.hassio] Failed to to call /network/info -
2021-03-08 23:49:49 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 314, in data_received
messages, upgraded, tail = self._request_parser.feed_data(data)
File "aiohttp/_http_parser.pyx", line 546, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'invalid HTTP method'"
2021-03-08 23:58:10 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 314, in data_received
messages, upgraded, tail = self._request_parser.feed_data(data)
File "aiohttp/_http_parser.pyx", line 546, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'invalid HTTP method'"
2021-03-09 00:01:52 ERROR (MainThread) [homeassistant.components.hassio.handler] /network/info return code 500
2021-03-09 00:01:52 ERROR (MainThread) [homeassistant.components.hassio] Failed to to call /network/info -
2021-03-09 00:21:24 ERROR (MainThread) [homeassistant.components.hassio.handler] /network/info return code 500
2021-03-09 00:21:24 ERROR (MainThread) [homeassistant.components.hassio] Failed to to call /network/info -
Supervisor logs:
21-03-31 14:44:34 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request
resp = await self._request_handler(request)
File "/usr/local/lib/python3.8/site-packages/sentry_sdk/integrations/aiohttp.py", line 123, in sentry_app_handle
reraise(*_capture_exception(hub))
File "/usr/local/lib/python3.8/site-packages/sentry_sdk/_compat.py", line 54, in reraise
raise value
File "/usr/local/lib/python3.8/site-packages/sentry_sdk/integrations/aiohttp.py", line 113, in sentry_app_handle
response = await old_handle(self, request)
File "/usr/local/lib/python3.8/site-packages/aiohttp/web_app.py", line 499, in _handle
resp = await handler(request)
File "/usr/local/lib/python3.8/site-packages/aiohttp/web_middlewares.py", line 119, in impl
return await handler(request)
File "/usr/src/supervisor/supervisor/api/security.py", line 135, in system_validation
return await handler(request)
File "/usr/src/supervisor/supervisor/api/security.py", line 197, in token_validation
return await handler(request)
File "/usr/src/supervisor/supervisor/api/utils.py", line 65, in wrap_api
answer = await method(api, *args, **kwargs)
File "/usr/src/supervisor/supervisor/api/network.py", line 166, in info
for interface in self.sys_host.network.interfaces
File "/usr/src/supervisor/supervisor/host/network.py", line 65, in interfaces
interfaces.append(Interface.from_dbus_interface(inet))
File "/usr/src/supervisor/supervisor/host/network.py", line 307, in from_dbus_interface
Interface._map_nm_wifi(inet),
File "/usr/src/supervisor/supervisor/host/network.py", line 352, in _map_nm_wifi
if inet.settings.wireless_security.key_mgmt == "none":
AttributeError: 'NoneType' object has no attribute 'key_mgmt'
I fixed the bug and here is my fixed network.py:
"""Info control for host."""from __future__ importannotationsimportasynciofromipaddressimportIPv4Address, IPv4Interface, IPv6Address, IPv6InterfaceimportloggingfromtypingimportList, Optional, Unionimportattrfrom ..constimportATTR_HOST_INTERNETfrom ..coresysimportCoreSys, CoreSysAttributesfrom ..dbus.constimport (
DBUS_NAME_NM_CONNECTION_ACTIVE_CHANGED,
ConnectionStateType,
DeviceType,
InterfaceMethodasNMInterfaceMethod,
WirelessMethodType,
)
from ..dbus.network.accesspointimportNetworkWirelessAPfrom ..dbus.network.connectionimportNetworkConnectionfrom ..dbus.network.interfaceimportNetworkInterfacefrom ..dbus.payloads.generateimportinterface_update_payloadfrom ..exceptionsimport (
DBusError,
DBusNotConnectedError,
DBusProgramError,
HostNetworkError,
HostNetworkNotFound,
HostNotSupportedError,
)
from .constimportAuthMethod, InterfaceMethod, InterfaceType, WifiMode_LOGGER: logging.Logger=logging.getLogger(__name__)
classNetworkManager(CoreSysAttributes):
"""Handle local network setup."""def__init__(self, coresys: CoreSys):
"""Initialize system center handling."""self.coresys: CoreSys=coresysself._connectivity: Optional[bool] =None@propertydefconnectivity(self) ->Optional[bool]:
"""Return true current connectivity state."""returnself._connectivity@connectivity.setterdefconnectivity(self, state: bool) ->None:
"""Set host connectivity state."""ifself._connectivity==state:
returnself._connectivity=stateself.sys_homeassistant.websocket.supervisor_update_event(
"network", {ATTR_HOST_INTERNET: state}
)
@propertydefinterfaces(self) ->List[Interface]:
"""Return a dictionary of active interfaces."""interfaces: List[Interface] = []
forinetinself.sys_dbus.network.interfaces.values():
interfaces.append(Interface.from_dbus_interface(inet))
returninterfaces@propertydefdns_servers(self) ->List[str]:
"""Return a list of local DNS servers."""# Read all local dns serversservers: List[str] = []
forconfiginself.sys_dbus.network.dns.configuration:
ifconfig.vpnornotconfig.nameservers:
continueservers.extend(config.nameservers)
returnlist(dict.fromkeys(servers))
asyncdefcheck_connectivity(self):
"""Check the internet connection. ConnectionState 4 == FULL (has internet) https://developer.gnome.org/NetworkManager/stable/nm-dbus-types.html#NMConnectivityState """ifnotself.sys_dbus.network.connectivity_enabled:
return# Check connectivitytry:
state=awaitself.sys_dbus.network.check_connectivity()
self.connectivity=state[0] ==4exceptDBusErroraserr:
_LOGGER.warning("Can't update connectivity information: %s", err)
self.connectivity=Falsedefget(self, inet_name: str) ->Interface:
"""Return interface from interface name."""ifinet_namenotinself.sys_dbus.network.interfaces:
raiseHostNetworkNotFound()
returnInterface.from_dbus_interface(
self.sys_dbus.network.interfaces[inet_name]
)
asyncdefupdate(self):
"""Update properties over dbus."""_LOGGER.info("Updating local network information")
try:
awaitself.sys_dbus.network.update()
exceptDBusError:
_LOGGER.warning("Can't update network information!")
exceptDBusNotConnectedErroraserr:
_LOGGER.error("No network D-Bus connection available")
raiseHostNotSupportedError() fromerrawaitself.check_connectivity()
asyncdefapply_changes(self, interface: Interface) ->None:
"""Apply Interface changes to host."""inet=self.sys_dbus.network.interfaces.get(interface.name)
# Update exist configurationif (
inetandinet.settingsandinet.settings.connection.interface_name==interface.nameandinterface.enabled
):
settings=interface_update_payload(
interface,
name=inet.settings.connection.id,
uuid=inet.settings.connection.uuid,
)
try:
awaitinet.settings.update(settings)
awaitself.sys_dbus.network.activate_connection(
inet.settings.object_path, inet.object_path
)
exceptDBusErroraserr:
_LOGGER.error("Can't update config on %s: %s", interface.name, err)
raiseHostNetworkError() fromerr# Create new configuration and activate interfaceelifinetandinterface.enabled:
settings=interface_update_payload(interface)
try:
awaitself.sys_dbus.network.add_and_activate_connection(
settings, inet.object_path
)
exceptDBusErroraserr:
_LOGGER.error(
"Can't create config and activate %s: %s", interface.name, err
)
raiseHostNetworkError() fromerr# Remove config from interfaceelifinetandinet.settingsandnotinterface.enabled:
try:
awaitinet.settings.delete()
exceptDBusErroraserr:
_LOGGER.error("Can't disable interface %s: %s", interface.name, err)
raiseHostNetworkError() fromerr# Create new interface (like vlan)elifnotinet:
settings=interface_update_payload(interface)
try:
awaitself.sys_dbus.network.settings.add_connection(settings)
exceptDBusErroraserr:
_LOGGER.error("Can't create new interface: %s", err)
raiseHostNetworkError() fromerrelse:
_LOGGER.warning("Requested Network interface update is not possible")
raiseHostNetworkError()
awaitself.sys_dbus.network.dbus.wait_signal(
DBUS_NAME_NM_CONNECTION_ACTIVE_CHANGED
)
awaitself.update()
asyncdefscan_wifi(self, interface: Interface) ->List[AccessPoint]:
"""Scan on Interface for AccessPoint."""inet=self.sys_dbus.network.interfaces.get(interface.name)
ifinet.type!=DeviceType.WIRELESS:
_LOGGER.error("Can only scan with wireless card - %s", interface.name)
raiseHostNotSupportedError()
# Request Scantry:
awaitinet.wireless.request_scan()
exceptDBusProgramErroraserr:
_LOGGER.debug("Can't request a new scan: %s", err)
exceptDBusErroraserr:
raiseHostNetworkError() fromerrelse:
awaitasyncio.sleep(5)
# Process APaccesspoints: List[AccessPoint] = []
forap_objectin (awaitinet.wireless.get_all_accesspoints())[0]:
accesspoint=NetworkWirelessAP(ap_object)
try:
awaitaccesspoint.connect()
exceptDBusErroraserr:
_LOGGER.warning("Can't process an AP: %s", err)
continueelse:
accesspoints.append(
AccessPoint(
WifiMode[WirelessMethodType(accesspoint.mode).name],
accesspoint.ssid,
accesspoint.mac,
accesspoint.frequency,
accesspoint.strength,
)
)
returnaccesspoints@attr.s(slots=True)classAccessPoint:
"""Represent a wifi configuration."""mode: WifiMode=attr.ib()
ssid: str=attr.ib()
mac: str=attr.ib()
frequency: int=attr.ib()
signal: int=attr.ib()
@attr.s(slots=True)classIpConfig:
"""Represent a IP configuration."""method: InterfaceMethod=attr.ib()
address: List[Union[IPv4Interface, IPv6Interface]] =attr.ib()
gateway: Optional[Union[IPv4Address, IPv6Address]] =attr.ib()
nameservers: List[Union[IPv4Address, IPv6Address]] =attr.ib()
@attr.s(slots=True)classWifiConfig:
"""Represent a wifi configuration."""mode: WifiMode=attr.ib()
ssid: str=attr.ib()
auth: AuthMethod=attr.ib()
psk: Optional[str] =attr.ib()
signal: Optional[int] =attr.ib()
@attr.s(slots=True)classVlanConfig:
"""Represent a vlan configuration."""id: int=attr.ib()
interface: str=attr.ib()
@attr.s(slots=True)classInterface:
"""Represent a host network interface."""name: str=attr.ib()
enabled: bool=attr.ib()
connected: bool=attr.ib()
primary: bool=attr.ib()
type: InterfaceType=attr.ib()
ipv4: Optional[IpConfig] =attr.ib()
ipv6: Optional[IpConfig] =attr.ib()
wifi: Optional[WifiConfig] =attr.ib()
vlan: Optional[VlanConfig] =attr.ib()
@staticmethoddeffrom_dbus_interface(inet: NetworkInterface) ->Interface:
"""Concert a dbus interface into normal Interface."""returnInterface(
inet.name,
inet.settingsisnotNone,
Interface._map_nm_connected(inet.connection),
inet.primary,
Interface._map_nm_type(inet.type),
IpConfig(
Interface._map_nm_method(inet.settings.ipv4.method),
inet.connection.ipv4.address,
inet.connection.ipv4.gateway,
inet.connection.ipv4.nameservers,
)
ifinet.connectionandinet.connection.ipv4elseIpConfig(InterfaceMethod.DISABLED, [], None, []),
IpConfig(
Interface._map_nm_method(inet.settings.ipv6.method),
inet.connection.ipv6.address,
inet.connection.ipv6.gateway,
inet.connection.ipv6.nameservers,
)
ifinet.connectionandinet.connection.ipv6elseIpConfig(InterfaceMethod.DISABLED, [], None, []),
Interface._map_nm_wifi(inet),
Interface._map_nm_vlan(inet),
)
@staticmethoddef_map_nm_method(method: str) ->InterfaceMethod:
"""Map IP interface method."""mapping= {
NMInterfaceMethod.AUTO: InterfaceMethod.AUTO,
NMInterfaceMethod.DISABLED: InterfaceMethod.DISABLED,
NMInterfaceMethod.MANUAL: InterfaceMethod.STATIC,
}
returnmapping.get(method, InterfaceMethod.DISABLED)
@staticmethoddef_map_nm_connected(connection: Optional[NetworkConnection]) ->bool:
"""Map connectivity state."""ifnotconnection:
returnFalsereturnconnection.statein (
ConnectionStateType.ACTIVATED,
ConnectionStateType.ACTIVATING,
)
@staticmethoddef_map_nm_type(device_type: int) ->InterfaceType:
mapping= {
DeviceType.ETHERNET: InterfaceType.ETHERNET,
DeviceType.WIRELESS: InterfaceType.WIRELESS,
DeviceType.VLAN: InterfaceType.VLAN,
}
returnmapping[device_type]
@staticmethoddef_map_nm_wifi(inet: NetworkInterface) ->Optional[WifiConfig]:
"""Create mapping to nm wifi property."""ifinet.type!=DeviceType.WIRELESSornotinet.settings:
returnNone# Authenticationauth=Noneifnotinet.settings.wireless_security:
auth=AuthMethod.OPENelifinet.settings.wireless_security.key_mgmt=="none":
auth=AuthMethod.WEPelifinet.settings.wireless_security.key_mgmt=="wpa-psk":
auth=AuthMethod.WPA_PSK# WifiModemode=WifiMode.INFRASTRUCTUREifinet.settings.wireless.mode:
mode=WifiMode(inet.settings.wireless.mode)
# Signalifinet.wireless:
signal=inet.wireless.active.strengthelse:
signal=Noneifnotinet.settings.wireless_security:
passwd=Noneelse:
passwd=inet.settings.wireless_security.pskreturnWifiConfig(
mode,
inet.settings.wireless.ssid,
auth,
passwd,
signal,
)
@staticmethoddef_map_nm_vlan(inet: NetworkInterface) ->Optional[WifiConfig]:
"""Create mapping to nm vlan property."""ifinet.type!=DeviceType.VLANornotinet.settings:
returnNonereturnVlanConfig(inet.settings.vlan.id, inet.settings.vlan.parent)
The text was updated successfully, but these errors were encountered:
Describe the issue you are experiencing
If host computer is connected to open wifi network, network.py script fails, /network/info page returns http code 500 and supervisor control panel cannot load
What is the used version of the Supervisor?
supervisor-2021.03.9
What type of installation are you running?
Home Assistant Supervised
Which operating system are you running on?
Other (e.g., Raspbian/Raspberry Pi OS/Fedora)
What is the version of your installed operating system?
Ubuntu 20.10 aarch64 for Raspberry PI 4
What version of Home Assistant Core is installed?
core-2021.3.4
Steps to reproduce the issue
Anything in the Supervisor logs that might be useful for us?
Core logs:
Supervisor logs:
I fixed the bug and here is my fixed network.py:
The text was updated successfully, but these errors were encountered: