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
73.7k stars 30.82k forks source link

Wemo integration error #53850

Closed bobflem closed 3 years ago

bobflem commented 3 years ago

The problem

Wemo integration is broken.

What is version of Home Assistant Core has the issue?

core-2021.7.4

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Belkin WeMo

Link to integration documentation on our website

https://www.home-assistant.io/integrations/wemo/

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2021-08-02 01:11:15 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Wemo for wemo
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/homeassistant/config_entries.py", line 293, in async_setup
result = await component.async_setup_entry(hass, self) # type: ignore
File "/usr/lib/python3.8/site-packages/homeassistant/components/wemo/__init__.py", line 133, in async_setup_entry
await wemo_discovery.async_discover_and_schedule()
File "/usr/lib/python3.8/site-packages/homeassistant/components/wemo/__init__.py", line 207, in async_discover_and_schedule
for device in await self._hass.async_add_executor_job(
File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/lib/python3.8/site-packages/pywemo/discovery.py", line 37, in discover_devices
device = device_from_uuid_and_location(
File "/usr/lib/python3.8/site-packages/pywemo/discovery.py", line 75, in device_from_uuid_and_location
return Switch(location)
File "/usr/lib/python3.8/site-packages/pywemo/ouimeaux_device/__init__.py", line 115, in __init__
self._config_any = {
File "/usr/lib/python3.8/site-packages/pywemo/ouimeaux_device/__init__.py", line 115, in <dictcomp>
self._config_any = {
File "/usr/lib/python3.8/site-packages/pywemo/ouimeaux_device/__init__.py", line 114, in <genexpr>
xs_any = (et.fromstring(extra) for extra in self._config.anytypeobjs_)
File "src/lxml/etree.pyx", line 3237, in lxml.etree.fromstring
File "src/lxml/parser.pxi", line 1896, in lxml.etree._parseMemoryDocument
File "src/lxml/parser.pxi", line 1777, in lxml.etree._parseDoc
File "src/lxml/parser.pxi", line 1082, in lxml.etree._BaseParser._parseUnicodeDoc
File "src/lxml/parser.pxi", line 615, in lxml.etree._ParserContext._handleParseResultDoc
File "src/lxml/parser.pxi", line 725, in lxml.etree._handleParseResult
File "src/lxml/parser.pxi", line 654, in lxml.etree._raiseParseError
File "<string>", line 2
lxml.etree.XMLSyntaxError: Extra content at the end of the document, line 2, column 5
2021-08-02 01:11:30 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/homeassistant/components/wemo/__init__.py", line 207, in async_discover_and_schedule
for device in await self._hass.async_add_executor_job(
File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/lib/python3.8/site-packages/pywemo/discovery.py", line 37, in discover_devices
device = device_from_uuid_and_location(
File "/usr/lib/python3.8/site-packages/pywemo/discovery.py", line 75, in device_from_uuid_and_location
return Switch(location)
File "/usr/lib/python3.8/site-packages/pywemo/ouimeaux_device/__init__.py", line 115, in __init__
self._config_any = {
File "/usr/lib/python3.8/site-packages/pywemo/ouimeaux_device/__init__.py", line 115, in <dictcomp>
self._config_any = {
File "/usr/lib/python3.8/site-packages/pywemo/ouimeaux_device/__init__.py", line 114, in <genexpr>
xs_any = (et.fromstring(extra) for extra in self._config.anytypeobjs_)
File "src/lxml/etree.pyx", line 3237, in lxml.etree.fromstring
File "src/lxml/parser.pxi", line 1896, in lxml.etree._parseMemoryDocument
File "src/lxml/parser.pxi", line 1777, in lxml.etree._parseDoc
File "src/lxml/parser.pxi", line 1082, in lxml.etree._BaseParser._parseUnicodeDoc
File "src/lxml/parser.pxi", line 615, in lxml.etree._ParserContext._handleParseResultDoc
File "src/lxml/parser.pxi", line 725, in lxml.etree._handleParseResult
File "src/lxml/parser.pxi", line 654, in lxml.etree._raiseParseError
File "<string>", line 2
lxml.etree.XMLSyntaxError: Extra content at the end of the document, line 2, column 5
2021-08-02 01:11:55 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/homeassistant/components/wemo/__init__.py", line 207, in async_discover_and_schedule
for device in await self._hass.async_add_executor_job(
File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/lib/python3.8/site-packages/pywemo/discovery.py", line 37, in discover_devices
device = device_from_uuid_and_location(
File "/usr/lib/python3.8/site-packages/pywemo/discovery.py", line 75, in device_from_uuid_and_location
return Switch(location)
File "/usr/lib/python3.8/site-packages/pywemo/ouimeaux_device/__init__.py", line 115, in __init__
self._config_any = {
File "/usr/lib/python3.8/site-packages/pywemo/ouimeaux_device/__init__.py", line 115, in <dictcomp>
self._config_any = {
File "/usr/lib/python3.8/site-packages/pywemo/ouimeaux_device/__init__.py", line 114, in <genexpr>
xs_any = (et.fromstring(extra) for extra in self._config.anytypeobjs_)
File "src/lxml/etree.pyx", line 3237, in lxml.etree.fromstring
File "src/lxml/parser.pxi", line 1896, in lxml.etree._parseMemoryDocument
File "src/lxml/parser.pxi", line 1777, in lxml.etree._parseDoc
File "src/lxml/parser.pxi", line 1082, in lxml.etree._BaseParser._parseUnicodeDoc
File "src/lxml/parser.pxi", line 615, in lxml.etree._ParserContext._handleParseResultDoc
File "src/lxml/parser.pxi", line 725, in lxml.etree._handleParseResult
File "src/lxml/parser.pxi", line 654, in lxml.etree._raiseParseError
File "<string>", line 2
lxml.etree.XMLSyntaxError: Extra content at the end of the document, line 2, column 5
2021-08-02 01:12:30 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/homeassistant/components/wemo/__init__.py", line 207, in async_discover_and_schedule
for device in await self._hass.async_add_executor_job(
File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/lib/python3.8/site-packages/pywemo/discovery.py", line 37, in discover_devices
device = device_from_uuid_and_location(
File "/usr/lib/python3.8/site-packages/pywemo/discovery.py", line 75, in device_from_uuid_and_location
return Switch(location)
File "/usr/lib/python3.8/site-packages/pywemo/ouimeaux_device/__init__.py", line 115, in __init__
self._config_any = {
File "/usr/lib/python3.8/site-packages/pywemo/ouimeaux_device/__init__.py", line 115, in <dictcomp>
self._config_any = {
File "/usr/lib/python3.8/site-packages/pywemo/ouimeaux_device/__init__.py", line 114, in <genexpr>
xs_any = (et.fromstring(extra) for extra in self._config.anytypeobjs_)
File "src/lxml/etree.pyx", line 3237, in lxml.etree.fromstring
File "src/lxml/parser.pxi", line 1896, in lxml.etree._parseMemoryDocument
File "src/lxml/parser.pxi", line 1777, in lxml.etree._parseDoc
File "src/lxml/parser.pxi", line 1082, in lxml.etree._BaseParser._parseUnicodeDoc
File "src/lxml/parser.pxi", line 615, in lxml.etree._ParserContext._handleParseResultDoc
File "src/lxml/parser.pxi", line 725, in lxml.etree._handleParseResult
File "src/lxml/parser.pxi", line 654, in lxml.etree._raiseParseError
File "<string>", line 2
lxml.etree.XMLSyntaxError: Extra content at the end of the document, line 2, column 5

Additional information

No response

probot-home-assistant[bot] commented 3 years ago

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


wemo documentation wemo source (message by IssueLinks)

esev commented 3 years ago

Hi @bobflem,

Thanks for the report. Could you help me gather more information about this issue? If you could, please run this Python code snippet. It'll help me diagnose how to proceed.

from lxml import etree
import pywemo

for entry in pywemo.ssdp.scan():
    if entry.match_device_description(
        {'manufacturer': 'Belkin International Inc.'}
    ):
        try:
            device = pywemo.discovery.device_from_uuid_and_location(
                entry.udn, entry.location
            )
        except pywemo.PyWeMoException:
            pass
        except etree.XMLSyntaxError:
            session = pywemo.ouimeaux_device.api.service.Session(entry.location)
            xml = session.get(entry.location)
            config = pywemo.ouimeaux_device.api.xsd.device.parseString(
                xml.content, silence=True, print_warnings=False
            ).device
            print(entry.location, config.get_friendlyName(), config.anytypeobjs_)

print(etree.LIBXML_VERSION)
bobflem commented 3 years ago

Here's the output: http://192.168.1.19:49153/setup.xml Server Room Light ['<hwVersion xmlns="urn:Belkin:device-1-0">v2</hwVersion>\n <modelURL>http://www.belkin.com/plugin/</modelURL>\n<serialNumber>221741K0105734</serialNumber>\n<UDN>uuid:Socket-1_0-221741K0105734</UDN>\n <UPC>123456789</UPC>\n<macAddress>58EF68FAB3E4</macAddress>\n<firmwareVersion>WeMo_WW_2.00.10971.PVT-OWRT-SNSV2</firmwareVersion>\n<iconVersion>7|49153</iconVersion>\n<binaryState>0</binaryState>\n <iconList>\n <icon>\n <mimetype>jpg</mimetype>\n <width>100</width>\n <height>100</height>\n <depth>100</depth>\n <url>icon.jpg</url>\n </icon>\n </iconList>\n <serviceList>\n <service>\n <serviceType>urn:Belkin:service:WiFiSetup:1</serviceType>\n <serviceId>urn:Belkin:serviceId:WiFiSetup1</serviceId>\n <controlURL>/upnp/control/WiFiSetup1</controlURL>\n <eventSubURL>/upnp/event/WiFiSetup1</eventSubURL>\n <SCPDURL>/setupservice.xml</SCPDURL>\n </service>\n <service>\n <serviceType>urn:Belkin:service:timesync:1</serviceType>\n <serviceId>urn:Belkin:serviceId:timesync1</serviceId>\n <controlURL>/upnp/control/timesync1</controlURL>\n <eventSubURL>/upnp/event/timesync1</eventSubURL>\n <SCPDURL>/timesyncservice.xml</SCPDURL>\n </service>\n <service>\n <serviceType>urn:Belkin:service:basicevent:1</serviceType>\n <serviceId>urn:Belkin:serviceId:basicevent1</serviceId>\n <controlURL>/upnp/control/basicevent1</controlURL>\n <eventSubURL>/upnp/event/basicevent1</eventSubURL>\n <SCPDURL>/eventservice.xml</SCPDURL>\n </service>\n <service>\n <serviceType>urn:Belkin:service:firmwareupdate:1</serviceType>\n <serviceId>urn:Belkin:serviceId:firmwareupdate1</serviceId>\n <controlURL>/upnp/control/firmwareupdate1</controlURL>\n <eventSubURL>/upnp/event/firmwareupdate1</eventSubURL>\n <SCPDURL>/firmwareupdate.xml</SCPDURL>\n </service>\n <service>\n <serviceType>urn:Belkin:service:rules:1</serviceType>\n <serviceId>urn:Belkin:serviceId:rules1</serviceId>\n <controlURL>/upnp/control/rules1</controlURL>\n <eventSubURL>/upnp/event/rules1</eventSubURL>\n <SCPDURL>/rulesservice.xml</SCPDURL>\n </service>\n\n <service>\n <serviceType>urn:Belkin:service:metainfo:1</serviceType>\n <serviceId>urn:Belkin:serviceId:metainfo1</serviceId>\n <controlURL>/upnp/control/metainfo1</controlURL>\n <eventSubURL>/upnp/event/metainfo1</eventSubURL>\n <SCPDURL>/metainfoservice.xml</SCPDURL>\n </service>\n\n <service>\n <serviceType>urn:Belkin:service:remoteaccess:1</serviceType>\n <serviceId>urn:Belkin:serviceId:remoteaccess1</serviceId>\n <controlURL>/upnp/control/remoteaccess1</controlURL>\n <eventSubURL>/upnp/event/remoteaccess1</eventSubURL>\n <SCPDURL>/remoteaccess.xml</SCPDURL>\n </service>\n\n <service>\n <serviceType>urn:Belkin:service:deviceinfo:1</serviceType>\n <serviceId>urn:Belkin:serviceId:deviceinfo1</serviceId>\n <controlURL>/upnp/control/deviceinfo1</controlURL>\n <eventSubURL>/upnp/event/deviceinfo1</eventSubURL>\n <SCPDURL>/deviceinfoservice.xml</SCPDURL>\n </service>\n\t \n <service>\n <serviceType>urn:Belkin:service:smartsetup:1</serviceType>\n <serviceId>urn:Belkin:serviceId:smartsetup1</serviceId>\n <controlURL>/upnp/control/smartsetup1</controlURL>\n <eventSubURL>/upnp/event/smartsetup1</eventSubURL>\n <SCPDURL>/smartsetup.xml</SCPDURL>\n </service>\n\t\n <service>\n <serviceType>urn:Belkin:service:manufacture:1</serviceType>\n <serviceId>urn:Belkin:serviceId:manufacture1</serviceId>\n <controlURL>/upnp/control/manufacture1</controlURL>\n <eventSubURL>/upnp/event/manufacture1</eventSubURL>\n <SCPDURL>/manufacture.xml</SCPDURL>\n </service>\n\n </serviceList>\n <presentationURL>/pluginpres.html</presentationURL>\n</device>\n</root>\n ', '<firmwareVersion xmlns="urn:Belkin:device-1-0">WeMo_WW_2.00.10971.PVT-OWRT-SNSV2</firmwareVersion>\n<iconVersion>7|49153</iconVersion>\n<binaryState>0</binaryState>\n <iconList>\n <icon>\n <mimetype>jpg</mimetype>\n <width>100</width>\n <height>100</height>\n <depth>100</depth>\n <url>icon.jpg</url>\n </icon>\n </iconList>\n <serviceList>\n <service>\n <serviceType>urn:Belkin:service:WiFiSetup:1</serviceType>\n <serviceId>urn:Belkin:serviceId:WiFiSetup1</serviceId>\n <controlURL>/upnp/control/WiFiSetup1</controlURL>\n <eventSubURL>/upnp/event/WiFiSetup1</eventSubURL>\n <SCPDURL>/setupservice.xml</SCPDURL>\n </service>\n <service>\n <serviceType>urn:Belkin:service:timesync:1</serviceType>\n <serviceId>urn:Belkin:serviceId:timesync1</serviceId>\n <controlURL>/upnp/control/timesync1</controlURL>\n <eventSubURL>/upnp/event/timesync1</eventSubURL>\n <SCPDURL>/timesyncservice.xml</SCPDURL>\n </service>\n <service>\n <serviceType>urn:Belkin:service:basicevent:1</serviceType>\n <serviceId>urn:Belkin:serviceId:basicevent1</serviceId>\n <controlURL>/upnp/control/basicevent1</controlURL>\n <eventSubURL>/upnp/event/basicevent1</eventSubURL>\n <SCPDURL>/eventservice.xml</SCPDURL>\n </service>\n <service>\n <serviceType>urn:Belkin:service:firmwareupdate:1</serviceType>\n <serviceId>urn:Belkin:serviceId:firmwareupdate1</serviceId>\n <controlURL>/upnp/control/firmwareupdate1</controlURL>\n <eventSubURL>/upnp/event/firmwareupdate1</eventSubURL>\n <SCPDURL>/firmwareupdate.xml</SCPDURL>\n </service>\n <service>\n <serviceType>urn:Belkin:service:rules:1</serviceType>\n <serviceId>urn:Belkin:serviceId:rules1</serviceId>\n <controlURL>/upnp/control/rules1</controlURL>\n <eventSubURL>/upnp/event/rules1</eventSubURL>\n <SCPDURL>/rulesservice.xml</SCPDURL>\n </service>\n\n <service>\n <serviceType>urn:Belkin:service:metainfo:1</serviceType>\n <serviceId>urn:Belkin:serviceId:metainfo1</serviceId>\n <controlURL>/upnp/control/metainfo1</controlURL>\n <eventSubURL>/upnp/event/metainfo1</eventSubURL>\n <SCPDURL>/metainfoservice.xml</SCPDURL>\n </service>\n\n <service>\n <serviceType>urn:Belkin:service:remoteaccess:1</serviceType>\n <serviceId>urn:Belkin:serviceId:remoteaccess1</serviceId>\n <controlURL>/upnp/control/remoteaccess1</controlURL>\n <eventSubURL>/upnp/event/remoteaccess1</eventSubURL>\n <SCPDURL>/remoteaccess.xml</SCPDURL>\n </service>\n\n <service>\n <serviceType>urn:Belkin:service:deviceinfo:1</serviceType>\n <serviceId>urn:Belkin:serviceId:deviceinfo1</serviceId>\n <controlURL>/upnp/control/deviceinfo1</controlURL>\n <eventSubURL>/upnp/event/deviceinfo1</eventSubURL>\n <SCPDURL>/deviceinfoservice.xml</SCPDURL>\n </service>\n\t \n <service>\n <serviceType>urn:Belkin:service:smartsetup:1</serviceType>\n <serviceId>urn:Belkin:serviceId:smartsetup1</serviceId>\n <controlURL>/upnp/control/smartsetup1</controlURL>\n <eventSubURL>/upnp/event/smartsetup1</eventSubURL>\n <SCPDURL>/smartsetup.xml</SCPDURL>\n </service>\n\t\n <service>\n <serviceType>urn:Belkin:service:manufacture:1</serviceType>\n <serviceId>urn:Belkin:serviceId:manufacture1</serviceId>\n <controlURL>/upnp/control/manufacture1</controlURL>\n <eventSubURL>/upnp/event/manufacture1</eventSubURL>\n <SCPDURL>/manufacture.xml</SCPDURL>\n </service>\n\n </serviceList>\n <presentationURL>/pluginpres.html</presentationURL>\n</device>\n</root>\n', '<iconVersion xmlns="urn:Belkin:device-1-0">7|49153</iconVersion>\n<binaryState>0</binaryState>\n <iconList>\n <icon>\n <mimetype>jpg</mimetype>\n <width>100</width>\n <height>100</height>\n <depth>100</depth>\n <url>icon.jpg</url>\n </icon>\n </iconList>\n <serviceList>\n <service>\n <serviceType>urn:Belkin:service:WiFiSetup:1</serviceType>\n <serviceId>urn:Belkin:serviceId:WiFiSetup1</serviceId>\n <controlURL>/upnp/control/WiFiSetup1</controlURL>\n <eventSubURL>/upnp/event/WiFiSetup1</eventSubURL>\n <SCPDURL>/setupservice.xml</SCPDURL>\n </service>\n <service>\n <serviceType>urn:Belkin:service:timesync:1</serviceType>\n <serviceId>urn:Belkin:serviceId:timesync1</serviceId>\n <controlURL>/upnp/control/timesync1</controlURL>\n <eventSubURL>/upnp/event/timesync1</eventSubURL>\n <SCPDURL>/timesyncservice.xml</SCPDURL>\n </service>\n <service>\n <serviceType>urn:Belkin:service:basicevent:1</serviceType>\n <serviceId>urn:Belkin:serviceId:basicevent1</serviceId>\n <controlURL>/upnp/control/basicevent1</controlURL>\n <eventSubURL>/upnp/event/basicevent1</eventSubURL>\n <SCPDURL>/eventservice.xml</SCPDURL>\n </service>\n <service>\n <serviceType>urn:Belkin:service:firmwareupdate:1</serviceType>\n <serviceId>urn:Belkin:serviceId:firmwareupdate1</serviceId>\n <controlURL>/upnp/control/firmwareupdate1</controlURL>\n <eventSubURL>/upnp/event/firmwareupdate1</eventSubURL>\n <SCPDURL>/firmwareupdate.xml</SCPDURL>\n </service>\n <service>\n <serviceType>urn:Belkin:service:rules:1</serviceType>\n <serviceId>urn:Belkin:serviceId:rules1</serviceId>\n <controlURL>/upnp/control/rules1</controlURL>\n <eventSubURL>/upnp/event/rules1</eventSubURL>\n <SCPDURL>/rulesservice.xml</SCPDURL>\n </service>\n\n <service>\n <serviceType>urn:Belkin:service:metainfo:1</serviceType>\n <serviceId>urn:Belkin:serviceId:metainfo1</serviceId>\n <controlURL>/upnp/control/metainfo1</controlURL>\n <eventSubURL>/upnp/event/metainfo1</eventSubURL>\n <SCPDURL>/metainfoservice.xml</SCPDURL>\n </service>\n\n <service>\n <serviceType>urn:Belkin:service:remoteaccess:1</serviceType>\n <serviceId>urn:Belkin:serviceId:remoteaccess1</serviceId>\n <controlURL>/upnp/control/remoteaccess1</controlURL>\n <eventSubURL>/upnp/event/remoteaccess1</eventSubURL>\n <SCPDURL>/remoteaccess.xml</SCPDURL>\n </service>\n\n <service>\n <serviceType>urn:Belkin:service:deviceinfo:1</serviceType>\n <serviceId>urn:Belkin:serviceId:deviceinfo1</serviceId>\n <controlURL>/upnp/control/deviceinfo1</controlURL>\n <eventSubURL>/upnp/event/deviceinfo1</eventSubURL>\n <SCPDURL>/deviceinfoservice.xml</SCPDURL>\n </service>\n\t \n <service>\n <serviceType>urn:Belkin:service:smartsetup:1</serviceType>\n <serviceId>urn:Belkin:serviceId:smartsetup1</serviceId>\n <controlURL>/upnp/control/smartsetup1</controlURL>\n <eventSubURL>/upnp/event/smartsetup1</eventSubURL>\n <SCPDURL>/smartsetup.xml</SCPDURL>\n </service>\n\t\n <service>\n <serviceType>urn:Belkin:service:manufacture:1</serviceType>\n <serviceId>urn:Belkin:serviceId:manufacture1</serviceId>\n <controlURL>/upnp/control/manufacture1</controlURL>\n <eventSubURL>/upnp/event/manufacture1</eventSubURL>\n <SCPDURL>/manufacture.xml</SCPDURL>\n </service>\n\n </serviceList>\n <presentationURL>/pluginpres.html</presentationURL>\n</device>\n</root>\n', '<binaryState xmlns="urn:Belkin:device-1-0">0</binaryState>\n <iconList>\n <icon>\n <mimetype>jpg</mimetype>\n <width>100</width>\n <height>100</height>\n <depth>100</depth>\n <url>icon.jpg</url>\n </icon>\n </iconList>\n <serviceList>\n <service>\n <serviceType>urn:Belkin:service:WiFiSetup:1</serviceType>\n <serviceId>urn:Belkin:serviceId:WiFiSetup1</serviceId>\n <controlURL>/upnp/control/WiFiSetup1</controlURL>\n <eventSubURL>/upnp/event/WiFiSetup1</eventSubURL>\n <SCPDURL>/setupservice.xml</SCPDURL>\n </service>\n <service>\n <serviceType>urn:Belkin:service:timesync:1</serviceType>\n <serviceId>urn:Belkin:serviceId:timesync1</serviceId>\n <controlURL>/upnp/control/timesync1</controlURL>\n <eventSubURL>/upnp/event/timesync1</eventSubURL>\n <SCPDURL>/timesyncservice.xml</SCPDURL>\n </service>\n <service>\n <serviceType>urn:Belkin:service:basicevent:1</serviceType>\n <serviceId>urn:Belkin:serviceId:basicevent1</serviceId>\n <controlURL>/upnp/control/basicevent1</controlURL>\n <eventSubURL>/upnp/event/basicevent1</eventSubURL>\n <SCPDURL>/eventservice.xml</SCPDURL>\n </service>\n <service>\n <serviceType>urn:Belkin:service:firmwareupdate:1</serviceType>\n <serviceId>urn:Belkin:serviceId:firmwareupdate1</serviceId>\n <controlURL>/upnp/control/firmwareupdate1</controlURL>\n <eventSubURL>/upnp/event/firmwareupdate1</eventSubURL>\n <SCPDURL>/firmwareupdate.xml</SCPDURL>\n </service>\n <service>\n <serviceType>urn:Belkin:service:rules:1</serviceType>\n <serviceId>urn:Belkin:serviceId:rules1</serviceId>\n <controlURL>/upnp/control/rules1</controlURL>\n <eventSubURL>/upnp/event/rules1</eventSubURL>\n <SCPDURL>/rulesservice.xml</SCPDURL>\n </service>\n\n <service>\n <serviceType>urn:Belkin:service:metainfo:1</serviceType>\n <serviceId>urn:Belkin:serviceId:metainfo1</serviceId>\n <controlURL>/upnp/control/metainfo1</controlURL>\n <eventSubURL>/upnp/event/metainfo1</eventSubURL>\n <SCPDURL>/metainfoservice.xml</SCPDURL>\n </service>\n\n <service>\n <serviceType>urn:Belkin:service:remoteaccess:1</serviceType>\n <serviceId>urn:Belkin:serviceId:remoteaccess1</serviceId>\n <controlURL>/upnp/control/remoteaccess1</controlURL>\n <eventSubURL>/upnp/event/remoteaccess1</eventSubURL>\n <SCPDURL>/remoteaccess.xml</SCPDURL>\n </service>\n\n <service>\n <serviceType>urn:Belkin:service:deviceinfo:1</serviceType>\n <serviceId>urn:Belkin:serviceId:deviceinfo1</serviceId>\n <controlURL>/upnp/control/deviceinfo1</controlURL>\n <eventSubURL>/upnp/event/deviceinfo1</eventSubURL>\n <SCPDURL>/deviceinfoservice.xml</SCPDURL>\n </service>\n\t \n <service>\n <serviceType>urn:Belkin:service:smartsetup:1</serviceType>\n <serviceId>urn:Belkin:serviceId:smartsetup1</serviceId>\n <controlURL>/upnp/control/smartsetup1</controlURL>\n <eventSubURL>/upnp/event/smartsetup1</eventSubURL>\n <SCPDURL>/smartsetup.xml</SCPDURL>\n </service>\n\t\n <service>\n <serviceType>urn:Belkin:service:manufacture:1</serviceType>\n <serviceId>urn:Belkin:serviceId:manufacture1</serviceId>\n <controlURL>/upnp/control/manufacture1</controlURL>\n <eventSubURL>/upnp/event/manufacture1</eventSubURL>\n <SCPDURL>/manufacture.xml</SCPDURL>\n </service>\n\n </serviceList>\n <presentationURL>/pluginpres.html</presentationURL>\n</device>\n</root>\n '] (2, 9, 12)

Thank you for taking a look

esev commented 3 years ago

You're welcome. Happy to help!

Could you download that http://192.168.1.19:49153/setup.xml file, and attach it to this issue?

Also, could you verify the version of lxml that is installed (pyWeMo requires at least version 4.6)? That way I can make sure I'm testing with the same version you have.

Here's what the version looks like inside the HA docker install:

bash-5.1# pip3 show lxml
Name: lxml
Version: 4.6.3
Summary: Powerful and Pythonic XML processing library combining libxml2/libxslt with the ElementTree API.
Home-page: https://lxml.de/
Author: lxml dev team
Author-email: lxml-dev@lxml.de
License: BSD
Location: /usr/local/lib/python3.9/site-packages
Requires: 
Required-by: zeep, uscisstatus, pywemo, pytrafikverket, PyRMVtransport, pyquery, pymeteoclimatic, pykmtronic, ProgettiHWSW, openhomedevice, MechanicalSoup, fritzprofiles, caldav, afsapi
bobflem commented 3 years ago

setup.xml.txt

Here's what I get from lxml:

Name: lxml
Version: 4.6.3
Summary: Powerful and Pythonic XML processing library combining libxml2/libxslt with the ElementTree API.
Home-page: https://lxml.de/
Author: lxml dev team
Author-email: lxml-dev@lxml.de
License: BSD
Location: /usr/lib/python3.8/site-packages
Requires: 
Required-by: zeep, uscisstatus, pywemo, pytrafikverket, PyRMVtransport, pyquery, pymeteoclimatic, pykmtronic, ProgettiHWSW, openhomedevice, MechanicalSoup, fritzprofiles, caldav, afsapi
esev commented 3 years ago

That's weird. For some reason I can't reproduce the issue with the attached setup.xml.txt file. Does this give the same output for you?

import pywemo

xml = b'''<PASTE_setup.xml.txt_HERE>'''
config = pywemo.ouimeaux_device.api.xsd.device.parseString(xml, silence=True, print_warnings=False)
config.device.anytypeobjs_

Output

>>> config.device.anytypeobjs_
['<hwVersion xmlns="urn:Belkin:device-1-0">v2</hwVersion>\n    ', '<firmwareVersion xmlns="urn:Belkin:device-1-0">WeMo_WW_2.00.10971.PVT-OWRT-SNSV2</firmwareVersion>\n', '<iconVersion xmlns="urn:Belkin:device-1-0">7|49153</iconVersion>\n', '<binaryState xmlns="urn:Belkin:device-1-0">0</binaryState>\n    ']

I think I can add a work-around for this XMLSyntaxError in pyWeMo. But I'd like to try to understand why it is parsing differently between our two systems. That way I can understand how to better prevent such issues in the future.

It's concerning that the <serviceList> appears in your original output. It might mean that even if I add the work-around pyWeMo still won't be parsing that xml file properly. Which could lead to yet another problem after the work-around is in place.

Maybe there is a odd character that isn't being handled correctly. Could you attach the output of this?

import pywemo
location = 'http://192.168.1.19:49153/setup.xml'
session = pywemo.ouimeaux_device.api.service.Session(location)
xml = session.get(location).content
print(repr(xml))

If you could feed that same output in place of the b'''<PASTE_setup.xml.txt_HERE>''' that would be very helpful too.

esev commented 3 years ago

@Spectre5 do you know what might be causing this? It looks like the xml isn't parsing properly with pywemo.ouimeaux_device.api.xsd.device.parseString.

bobflem commented 3 years ago

I get something a heck of a lot longer than what you got:

>>> config.device.anytypeobjs_
['<hwVersion xmlns="urn:Belkin:device-1-0">v2</hwVersion>\n    <modelURL>http://www.belkin.com/plugin/</modelURL>\n<serialNumber>221741K0105734</serialNumber>\n<UDN>uuid:Socket-1_0-221741K0105734</UDN>\n    <UPC>123456789</UPC>\n<macAddress>58EF68FAB3E4</macAddress>\n<firmwareVersion>WeMo_WW_2.00.10971.PVT-OWRT-SNSV2</firmwareVersion>\n<iconVersion>7|49153</iconVersion>\n<binaryState>0</binaryState>\n    <iconList>\n      <icon>\n        <mimetype>jpg</mimetype>\n        <width>100</width>\n        <height>100</height>\n        <depth>100</depth>\n         <url>icon.jpg</url>\n      </icon>\n    </iconList>\n    <serviceList>\n      <service>\n        <serviceType>urn:Belkin:service:WiFiSetup:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:WiFiSetup1</serviceId>\n        <controlURL>/upnp/control/WiFiSetup1</controlURL>\n        <eventSubURL>/upnp/event/WiFiSetup1</eventSubURL>\n        <SCPDURL>/setupservice.xml</SCPDURL>\n      </service>\n      <service>\n        <serviceType>urn:Belkin:service:timesync:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:timesync1</serviceId>\n        <controlURL>/upnp/control/timesync1</controlURL>\n        <eventSubURL>/upnp/event/timesync1</eventSubURL>\n        <SCPDURL>/timesyncservice.xml</SCPDURL>\n      </service>\n      <service>\n        <serviceType>urn:Belkin:service:basicevent:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:basicevent1</serviceId>\n        <controlURL>/upnp/control/basicevent1</controlURL>\n        <eventSubURL>/upnp/event/basicevent1</eventSubURL>\n        <SCPDURL>/eventservice.xml</SCPDURL>\n      </service>\n      <service>\n        <serviceType>urn:Belkin:service:firmwareupdate:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:firmwareupdate1</serviceId>\n        <controlURL>/upnp/control/firmwareupdate1</controlURL>\n        <eventSubURL>/upnp/event/firmwareupdate1</eventSubURL>\n        <SCPDURL>/firmwareupdate.xml</SCPDURL>\n      </service>\n      <service>\n        <serviceType>urn:Belkin:service:rules:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:rules1</serviceId>\n        <controlURL>/upnp/control/rules1</controlURL>\n        <eventSubURL>/upnp/event/rules1</eventSubURL>\n        <SCPDURL>/rulesservice.xml</SCPDURL>\n      </service>\n\n      <service>\n        <serviceType>urn:Belkin:service:metainfo:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:metainfo1</serviceId>\n        <controlURL>/upnp/control/metainfo1</controlURL>\n        <eventSubURL>/upnp/event/metainfo1</eventSubURL>\n        <SCPDURL>/metainfoservice.xml</SCPDURL>\n      </service>\n\n      <service>\n        <serviceType>urn:Belkin:service:remoteaccess:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:remoteaccess1</serviceId>\n        <controlURL>/upnp/control/remoteaccess1</controlURL>\n        <eventSubURL>/upnp/event/remoteaccess1</eventSubURL>\n        <SCPDURL>/remoteaccess.xml</SCPDURL>\n      </service>\n\n      <service>\n        <serviceType>urn:Belkin:service:deviceinfo:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:deviceinfo1</serviceId>\n        <controlURL>/upnp/control/deviceinfo1</controlURL>\n        <eventSubURL>/upnp/event/deviceinfo1</eventSubURL>\n        <SCPDURL>/deviceinfoservice.xml</SCPDURL>\n      </service>\n\t   \n      <service>\n        <serviceType>urn:Belkin:service:smartsetup:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:smartsetup1</serviceId>\n        <controlURL>/upnp/control/smartsetup1</controlURL>\n        <eventSubURL>/upnp/event/smartsetup1</eventSubURL>\n        <SCPDURL>/smartsetup.xml</SCPDURL>\n      </service>\n\t\n      <service>\n        <serviceType>urn:Belkin:service:manufacture:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:manufacture1</serviceId>\n        <controlURL>/upnp/control/manufacture1</controlURL>\n        <eventSubURL>/upnp/event/manufacture1</eventSubURL>\n        <SCPDURL>/manufacture.xml</SCPDURL>\n      </service>\n\n    </serviceList>\n   <presentationURL>/pluginpres.html</presentationURL>\n</device>\n</root>\n    ', '<firmwareVersion xmlns="urn:Belkin:device-1-0">WeMo_WW_2.00.10971.PVT-OWRT-SNSV2</firmwareVersion>\n<iconVersion>7|49153</iconVersion>\n<binaryState>0</binaryState>\n    <iconList>\n      <icon>\n        <mimetype>jpg</mimetype>\n        <width>100</width>\n        <height>100</height>\n        <depth>100</depth>\n         <url>icon.jpg</url>\n      </icon>\n    </iconList>\n    <serviceList>\n      <service>\n        <serviceType>urn:Belkin:service:WiFiSetup:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:WiFiSetup1</serviceId>\n        <controlURL>/upnp/control/WiFiSetup1</controlURL>\n        <eventSubURL>/upnp/event/WiFiSetup1</eventSubURL>\n        <SCPDURL>/setupservice.xml</SCPDURL>\n      </service>\n      <service>\n        <serviceType>urn:Belkin:service:timesync:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:timesync1</serviceId>\n        <controlURL>/upnp/control/timesync1</controlURL>\n        <eventSubURL>/upnp/event/timesync1</eventSubURL>\n        <SCPDURL>/timesyncservice.xml</SCPDURL>\n      </service>\n      <service>\n        <serviceType>urn:Belkin:service:basicevent:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:basicevent1</serviceId>\n        <controlURL>/upnp/control/basicevent1</controlURL>\n        <eventSubURL>/upnp/event/basicevent1</eventSubURL>\n        <SCPDURL>/eventservice.xml</SCPDURL>\n      </service>\n      <service>\n        <serviceType>urn:Belkin:service:firmwareupdate:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:firmwareupdate1</serviceId>\n        <controlURL>/upnp/control/firmwareupdate1</controlURL>\n        <eventSubURL>/upnp/event/firmwareupdate1</eventSubURL>\n        <SCPDURL>/firmwareupdate.xml</SCPDURL>\n      </service>\n      <service>\n        <serviceType>urn:Belkin:service:rules:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:rules1</serviceId>\n        <controlURL>/upnp/control/rules1</controlURL>\n        <eventSubURL>/upnp/event/rules1</eventSubURL>\n        <SCPDURL>/rulesservice.xml</SCPDURL>\n      </service>\n\n      <service>\n        <serviceType>urn:Belkin:service:metainfo:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:metainfo1</serviceId>\n        <controlURL>/upnp/control/metainfo1</controlURL>\n        <eventSubURL>/upnp/event/metainfo1</eventSubURL>\n        <SCPDURL>/metainfoservice.xml</SCPDURL>\n      </service>\n\n      <service>\n        <serviceType>urn:Belkin:service:remoteaccess:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:remoteaccess1</serviceId>\n        <controlURL>/upnp/control/remoteaccess1</controlURL>\n        <eventSubURL>/upnp/event/remoteaccess1</eventSubURL>\n        <SCPDURL>/remoteaccess.xml</SCPDURL>\n      </service>\n\n      <service>\n        <serviceType>urn:Belkin:service:deviceinfo:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:deviceinfo1</serviceId>\n        <controlURL>/upnp/control/deviceinfo1</controlURL>\n        <eventSubURL>/upnp/event/deviceinfo1</eventSubURL>\n        <SCPDURL>/deviceinfoservice.xml</SCPDURL>\n      </service>\n\t   \n      <service>\n        <serviceType>urn:Belkin:service:smartsetup:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:smartsetup1</serviceId>\n        <controlURL>/upnp/control/smartsetup1</controlURL>\n        <eventSubURL>/upnp/event/smartsetup1</eventSubURL>\n        <SCPDURL>/smartsetup.xml</SCPDURL>\n      </service>\n\t\n      <service>\n        <serviceType>urn:Belkin:service:manufacture:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:manufacture1</serviceId>\n        <controlURL>/upnp/control/manufacture1</controlURL>\n        <eventSubURL>/upnp/event/manufacture1</eventSubURL>\n        <SCPDURL>/manufacture.xml</SCPDURL>\n      </service>\n\n    </serviceList>\n   <presentationURL>/pluginpres.html</presentationURL>\n</device>\n</root>\n', '<iconVersion xmlns="urn:Belkin:device-1-0">7|49153</iconVersion>\n<binaryState>0</binaryState>\n    <iconList>\n      <icon>\n        <mimetype>jpg</mimetype>\n        <width>100</width>\n        <height>100</height>\n        <depth>100</depth>\n         <url>icon.jpg</url>\n      </icon>\n    </iconList>\n    <serviceList>\n      <service>\n        <serviceType>urn:Belkin:service:WiFiSetup:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:WiFiSetup1</serviceId>\n        <controlURL>/upnp/control/WiFiSetup1</controlURL>\n        <eventSubURL>/upnp/event/WiFiSetup1</eventSubURL>\n        <SCPDURL>/setupservice.xml</SCPDURL>\n      </service>\n      <service>\n        <serviceType>urn:Belkin:service:timesync:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:timesync1</serviceId>\n        <controlURL>/upnp/control/timesync1</controlURL>\n        <eventSubURL>/upnp/event/timesync1</eventSubURL>\n        <SCPDURL>/timesyncservice.xml</SCPDURL>\n      </service>\n      <service>\n        <serviceType>urn:Belkin:service:basicevent:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:basicevent1</serviceId>\n        <controlURL>/upnp/control/basicevent1</controlURL>\n        <eventSubURL>/upnp/event/basicevent1</eventSubURL>\n        <SCPDURL>/eventservice.xml</SCPDURL>\n      </service>\n      <service>\n        <serviceType>urn:Belkin:service:firmwareupdate:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:firmwareupdate1</serviceId>\n        <controlURL>/upnp/control/firmwareupdate1</controlURL>\n        <eventSubURL>/upnp/event/firmwareupdate1</eventSubURL>\n        <SCPDURL>/firmwareupdate.xml</SCPDURL>\n      </service>\n      <service>\n        <serviceType>urn:Belkin:service:rules:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:rules1</serviceId>\n        <controlURL>/upnp/control/rules1</controlURL>\n        <eventSubURL>/upnp/event/rules1</eventSubURL>\n        <SCPDURL>/rulesservice.xml</SCPDURL>\n      </service>\n\n      <service>\n        <serviceType>urn:Belkin:service:metainfo:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:metainfo1</serviceId>\n        <controlURL>/upnp/control/metainfo1</controlURL>\n        <eventSubURL>/upnp/event/metainfo1</eventSubURL>\n        <SCPDURL>/metainfoservice.xml</SCPDURL>\n      </service>\n\n      <service>\n        <serviceType>urn:Belkin:service:remoteaccess:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:remoteaccess1</serviceId>\n        <controlURL>/upnp/control/remoteaccess1</controlURL>\n        <eventSubURL>/upnp/event/remoteaccess1</eventSubURL>\n        <SCPDURL>/remoteaccess.xml</SCPDURL>\n      </service>\n\n      <service>\n        <serviceType>urn:Belkin:service:deviceinfo:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:deviceinfo1</serviceId>\n        <controlURL>/upnp/control/deviceinfo1</controlURL>\n        <eventSubURL>/upnp/event/deviceinfo1</eventSubURL>\n        <SCPDURL>/deviceinfoservice.xml</SCPDURL>\n      </service>\n\t   \n      <service>\n        <serviceType>urn:Belkin:service:smartsetup:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:smartsetup1</serviceId>\n        <controlURL>/upnp/control/smartsetup1</controlURL>\n        <eventSubURL>/upnp/event/smartsetup1</eventSubURL>\n        <SCPDURL>/smartsetup.xml</SCPDURL>\n      </service>\n\t\n      <service>\n        <serviceType>urn:Belkin:service:manufacture:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:manufacture1</serviceId>\n        <controlURL>/upnp/control/manufacture1</controlURL>\n        <eventSubURL>/upnp/event/manufacture1</eventSubURL>\n        <SCPDURL>/manufacture.xml</SCPDURL>\n      </service>\n\n    </serviceList>\n   <presentationURL>/pluginpres.html</presentationURL>\n</device>\n</root>\n', '<binaryState xmlns="urn:Belkin:device-1-0">0</binaryState>\n    <iconList>\n      <icon>\n        <mimetype>jpg</mimetype>\n        <width>100</width>\n        <height>100</height>\n        <depth>100</depth>\n         <url>icon.jpg</url>\n      </icon>\n    </iconList>\n    <serviceList>\n      <service>\n        <serviceType>urn:Belkin:service:WiFiSetup:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:WiFiSetup1</serviceId>\n        <controlURL>/upnp/control/WiFiSetup1</controlURL>\n        <eventSubURL>/upnp/event/WiFiSetup1</eventSubURL>\n        <SCPDURL>/setupservice.xml</SCPDURL>\n      </service>\n      <service>\n        <serviceType>urn:Belkin:service:timesync:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:timesync1</serviceId>\n        <controlURL>/upnp/control/timesync1</controlURL>\n        <eventSubURL>/upnp/event/timesync1</eventSubURL>\n        <SCPDURL>/timesyncservice.xml</SCPDURL>\n      </service>\n      <service>\n        <serviceType>urn:Belkin:service:basicevent:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:basicevent1</serviceId>\n        <controlURL>/upnp/control/basicevent1</controlURL>\n        <eventSubURL>/upnp/event/basicevent1</eventSubURL>\n        <SCPDURL>/eventservice.xml</SCPDURL>\n      </service>\n      <service>\n        <serviceType>urn:Belkin:service:firmwareupdate:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:firmwareupdate1</serviceId>\n        <controlURL>/upnp/control/firmwareupdate1</controlURL>\n        <eventSubURL>/upnp/event/firmwareupdate1</eventSubURL>\n        <SCPDURL>/firmwareupdate.xml</SCPDURL>\n      </service>\n      <service>\n        <serviceType>urn:Belkin:service:rules:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:rules1</serviceId>\n        <controlURL>/upnp/control/rules1</controlURL>\n        <eventSubURL>/upnp/event/rules1</eventSubURL>\n        <SCPDURL>/rulesservice.xml</SCPDURL>\n      </service>\n\n      <service>\n        <serviceType>urn:Belkin:service:metainfo:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:metainfo1</serviceId>\n        <controlURL>/upnp/control/metainfo1</controlURL>\n        <eventSubURL>/upnp/event/metainfo1</eventSubURL>\n        <SCPDURL>/metainfoservice.xml</SCPDURL>\n      </service>\n\n      <service>\n        <serviceType>urn:Belkin:service:remoteaccess:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:remoteaccess1</serviceId>\n        <controlURL>/upnp/control/remoteaccess1</controlURL>\n        <eventSubURL>/upnp/event/remoteaccess1</eventSubURL>\n        <SCPDURL>/remoteaccess.xml</SCPDURL>\n      </service>\n\n      <service>\n        <serviceType>urn:Belkin:service:deviceinfo:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:deviceinfo1</serviceId>\n        <controlURL>/upnp/control/deviceinfo1</controlURL>\n        <eventSubURL>/upnp/event/deviceinfo1</eventSubURL>\n        <SCPDURL>/deviceinfoservice.xml</SCPDURL>\n      </service>\n\t   \n      <service>\n        <serviceType>urn:Belkin:service:smartsetup:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:smartsetup1</serviceId>\n        <controlURL>/upnp/control/smartsetup1</controlURL>\n        <eventSubURL>/upnp/event/smartsetup1</eventSubURL>\n        <SCPDURL>/smartsetup.xml</SCPDURL>\n      </service>\n\t\n      <service>\n        <serviceType>urn:Belkin:service:manufacture:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:manufacture1</serviceId>\n        <controlURL>/upnp/control/manufacture1</controlURL>\n        <eventSubURL>/upnp/event/manufacture1</eventSubURL>\n        <SCPDURL>/manufacture.xml</SCPDURL>\n      </service>\n\n    </serviceList>\n   <presentationURL>/pluginpres.html</presentationURL>\n</device>\n</root>\n    ']

Here's the output of the second code block:

>>> print(repr(xml))
b'<?xml version="1.0"?>\n<root xmlns="urn:Belkin:device-1-0">\n  <specVersion>\n    <major>1</major>\n    <minor>0</minor>\n  </specVersion>\n  <device>\n<deviceType>urn:Belkin:device:controllee:1</deviceType>\n<friendlyName>Server Room Light</friendlyName>\n    <manufacturer>Belkin International Inc.</manufacturer>\n    <manufacturerURL>http://www.belkin.com</manufacturerURL>\n    <modelDescription>Belkin Plugin Socket 1.0</modelDescription>\n<modelName>Socket</modelName>\n    <modelNumber>1.0</modelNumber>\n<hwVersion>v2</hwVersion>\n    <modelURL>http://www.belkin.com/plugin/</modelURL>\n<serialNumber>221741K0105734</serialNumber>\n<UDN>uuid:Socket-1_0-221741K0105734</UDN>\n    <UPC>123456789</UPC>\n<macAddress>58EF68FAB3E4</macAddress>\n<firmwareVersion>WeMo_WW_2.00.10971.PVT-OWRT-SNSV2</firmwareVersion>\n<iconVersion>7|49153</iconVersion>\n<binaryState>0</binaryState>\n    <iconList>\n      <icon>\n        <mimetype>jpg</mimetype>\n        <width>100</width>\n        <height>100</height>\n        <depth>100</depth>\n         <url>icon.jpg</url>\n      </icon>\n    </iconList>\n    <serviceList>\n      <service>\n        <serviceType>urn:Belkin:service:WiFiSetup:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:WiFiSetup1</serviceId>\n        <controlURL>/upnp/control/WiFiSetup1</controlURL>\n        <eventSubURL>/upnp/event/WiFiSetup1</eventSubURL>\n        <SCPDURL>/setupservice.xml</SCPDURL>\n      </service>\n      <service>\n        <serviceType>urn:Belkin:service:timesync:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:timesync1</serviceId>\n        <controlURL>/upnp/control/timesync1</controlURL>\n        <eventSubURL>/upnp/event/timesync1</eventSubURL>\n        <SCPDURL>/timesyncservice.xml</SCPDURL>\n      </service>\n      <service>\n        <serviceType>urn:Belkin:service:basicevent:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:basicevent1</serviceId>\n        <controlURL>/upnp/control/basicevent1</controlURL>\n        <eventSubURL>/upnp/event/basicevent1</eventSubURL>\n        <SCPDURL>/eventservice.xml</SCPDURL>\n      </service>\n      <service>\n        <serviceType>urn:Belkin:service:firmwareupdate:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:firmwareupdate1</serviceId>\n        <controlURL>/upnp/control/firmwareupdate1</controlURL>\n        <eventSubURL>/upnp/event/firmwareupdate1</eventSubURL>\n        <SCPDURL>/firmwareupdate.xml</SCPDURL>\n      </service>\n      <service>\n        <serviceType>urn:Belkin:service:rules:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:rules1</serviceId>\n        <controlURL>/upnp/control/rules1</controlURL>\n        <eventSubURL>/upnp/event/rules1</eventSubURL>\n        <SCPDURL>/rulesservice.xml</SCPDURL>\n      </service>\n\n      <service>\n        <serviceType>urn:Belkin:service:metainfo:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:metainfo1</serviceId>\n        <controlURL>/upnp/control/metainfo1</controlURL>\n        <eventSubURL>/upnp/event/metainfo1</eventSubURL>\n        <SCPDURL>/metainfoservice.xml</SCPDURL>\n      </service>\n\n      <service>\n        <serviceType>urn:Belkin:service:remoteaccess:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:remoteaccess1</serviceId>\n        <controlURL>/upnp/control/remoteaccess1</controlURL>\n        <eventSubURL>/upnp/event/remoteaccess1</eventSubURL>\n        <SCPDURL>/remoteaccess.xml</SCPDURL>\n      </service>\n\n      <service>\n        <serviceType>urn:Belkin:service:deviceinfo:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:deviceinfo1</serviceId>\n        <controlURL>/upnp/control/deviceinfo1</controlURL>\n        <eventSubURL>/upnp/event/deviceinfo1</eventSubURL>\n        <SCPDURL>/deviceinfoservice.xml</SCPDURL>\n      </service>\n\t   \n      <service>\n        <serviceType>urn:Belkin:service:smartsetup:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:smartsetup1</serviceId>\n        <controlURL>/upnp/control/smartsetup1</controlURL>\n        <eventSubURL>/upnp/event/smartsetup1</eventSubURL>\n        <SCPDURL>/smartsetup.xml</SCPDURL>\n      </service>\n\t\n      <service>\n        <serviceType>urn:Belkin:service:manufacture:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:manufacture1</serviceId>\n        <controlURL>/upnp/control/manufacture1</controlURL>\n        <eventSubURL>/upnp/event/manufacture1</eventSubURL>\n        <SCPDURL>/manufacture.xml</SCPDURL>\n      </service>\n\n    </serviceList>\n   <presentationURL>/pluginpres.html</presentationURL>\n</device>\n</root>\n'
esev commented 3 years ago

Thanks @bobflem. This is all very helpful!

My concern is that if this is failing, maybe the services aren't being parsed properly either. Let's verify that.

I get 10 as the output for this:

import pywemo
xml = b'<?xml version="1.0"?>\n<root xmlns="urn:Belkin:device-1-0">\n  <specVersion>\n    <major>1</major>\n    <minor>0</minor>\n  </specVersion>\n  <device>\n<deviceType>urn:Belkin:device:controllee:1</deviceType>\n<friendlyName>Server Room Light</friendlyName>\n    <manufacturer>Belkin International Inc.</manufacturer>\n    <manufacturerURL>http://www.belkin.com</manufacturerURL>\n    <modelDescription>Belkin Plugin Socket 1.0</modelDescription>\n<modelName>Socket</modelName>\n    <modelNumber>1.0</modelNumber>\n<hwVersion>v2</hwVersion>\n    <modelURL>http://www.belkin.com/plugin/</modelURL>\n<serialNumber>221741K0105734</serialNumber>\n<UDN>uuid:Socket-1_0-221741K0105734</UDN>\n    <UPC>123456789</UPC>\n<macAddress>58EF68FAB3E4</macAddress>\n<firmwareVersion>WeMo_WW_2.00.10971.PVT-OWRT-SNSV2</firmwareVersion>\n<iconVersion>7|49153</iconVersion>\n<binaryState>0</binaryState>\n    <iconList>\n      <icon>\n        <mimetype>jpg</mimetype>\n        <width>100</width>\n        <height>100</height>\n        <depth>100</depth>\n         <url>icon.jpg</url>\n      </icon>\n    </iconList>\n    <serviceList>\n      <service>\n        <serviceType>urn:Belkin:service:WiFiSetup:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:WiFiSetup1</serviceId>\n        <controlURL>/upnp/control/WiFiSetup1</controlURL>\n        <eventSubURL>/upnp/event/WiFiSetup1</eventSubURL>\n        <SCPDURL>/setupservice.xml</SCPDURL>\n      </service>\n      <service>\n        <serviceType>urn:Belkin:service:timesync:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:timesync1</serviceId>\n        <controlURL>/upnp/control/timesync1</controlURL>\n        <eventSubURL>/upnp/event/timesync1</eventSubURL>\n        <SCPDURL>/timesyncservice.xml</SCPDURL>\n      </service>\n      <service>\n        <serviceType>urn:Belkin:service:basicevent:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:basicevent1</serviceId>\n        <controlURL>/upnp/control/basicevent1</controlURL>\n        <eventSubURL>/upnp/event/basicevent1</eventSubURL>\n        <SCPDURL>/eventservice.xml</SCPDURL>\n      </service>\n      <service>\n        <serviceType>urn:Belkin:service:firmwareupdate:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:firmwareupdate1</serviceId>\n        <controlURL>/upnp/control/firmwareupdate1</controlURL>\n        <eventSubURL>/upnp/event/firmwareupdate1</eventSubURL>\n        <SCPDURL>/firmwareupdate.xml</SCPDURL>\n      </service>\n      <service>\n        <serviceType>urn:Belkin:service:rules:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:rules1</serviceId>\n        <controlURL>/upnp/control/rules1</controlURL>\n        <eventSubURL>/upnp/event/rules1</eventSubURL>\n        <SCPDURL>/rulesservice.xml</SCPDURL>\n      </service>\n\n      <service>\n        <serviceType>urn:Belkin:service:metainfo:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:metainfo1</serviceId>\n        <controlURL>/upnp/control/metainfo1</controlURL>\n        <eventSubURL>/upnp/event/metainfo1</eventSubURL>\n        <SCPDURL>/metainfoservice.xml</SCPDURL>\n      </service>\n\n      <service>\n        <serviceType>urn:Belkin:service:remoteaccess:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:remoteaccess1</serviceId>\n        <controlURL>/upnp/control/remoteaccess1</controlURL>\n        <eventSubURL>/upnp/event/remoteaccess1</eventSubURL>\n        <SCPDURL>/remoteaccess.xml</SCPDURL>\n      </service>\n\n      <service>\n        <serviceType>urn:Belkin:service:deviceinfo:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:deviceinfo1</serviceId>\n        <controlURL>/upnp/control/deviceinfo1</controlURL>\n        <eventSubURL>/upnp/event/deviceinfo1</eventSubURL>\n        <SCPDURL>/deviceinfoservice.xml</SCPDURL>\n      </service>\n\t   \n      <service>\n        <serviceType>urn:Belkin:service:smartsetup:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:smartsetup1</serviceId>\n        <controlURL>/upnp/control/smartsetup1</controlURL>\n        <eventSubURL>/upnp/event/smartsetup1</eventSubURL>\n        <SCPDURL>/smartsetup.xml</SCPDURL>\n      </service>\n\t\n      <service>\n        <serviceType>urn:Belkin:service:manufacture:1</serviceType>\n        <serviceId>urn:Belkin:serviceId:manufacture1</serviceId>\n        <controlURL>/upnp/control/manufacture1</controlURL>\n        <eventSubURL>/upnp/event/manufacture1</eventSubURL>\n        <SCPDURL>/manufacture.xml</SCPDURL>\n      </service>\n\n    </serviceList>\n   <presentationURL>/pluginpres.html</presentationURL>\n</device>\n</root>\n'
config = pywemo.ouimeaux_device.api.xsd.device.parseString(xml, silence=True, print_warnings=False)
print(len(config.device.serviceList.service))

If you get 10 also, then I think the simple work-around that I'm considering will work.

Which OS/hardware is this running on? I'll keep trying to reproduce the issue.

bobflem commented 3 years ago

I got 10 as well. HA is running on docker, and docker is running on Unraid 6.9.2 on a Dell R710 LFF.

Feel free to ask any questions you might have for me, I'll do my best to answer.

Spectre5 commented 3 years ago

I can take a look at this tomorrow evening if you guys don't make progress by then!

What version of lxml do you have though? Is it possible the wrong version is installed do to a conflict with another component?

esev commented 3 years ago

Thanks @Spectre5!

@bobflem and I are both using lxml version 4.6.3 (confirmed with pip3 show lxml), though our etree.LIBXML_VERSION is different: (2, 9, 12) vs (2, 9, 10). I have the older one.

Spectre5 commented 3 years ago

Yup, just saw it from a quick scan of higher up now. Just wanted to make sure that was checked first.

esev commented 3 years ago

@bobflem I'd like to try to replicate on a system with that same etree.LIBXML_VERSION. You mentioned you were running HA in a docker container. Could you share where you got the docker image from, or what the base/FROM image is in the Dockerfile?

bobflem commented 3 years ago

The image I'm using is ghcr.io/linuxserver/homeassistant

esev commented 3 years ago

I think the issue might be due a version mismatch between the Python lxml library and the C libxml2 library. https://bugs.launchpad.net/lxml/+bug/1928795

It seems lxml only supports up to version 2.9.10 of libxml2. The bugs mention the same behavior we're seeing. Specifically:

Due to internal impl changes in 2.9.12, this results in garbage being printed after XML elements.

I think this is specific to the linuxserver Home Assistant container (ghcr.io/linuxserver/homeassistant). The official/supported ghcr.io/home-assistant/home-assistant version is using libxml2 version 2.9.10.

That said, I think I understand why the linuxserver image uses this version. I'm betting they've updated the version of libxml2 for CVE-2021-3541. Unfortunately, at the moment, this also breaks the lxml Python package.

I see that a number of other Home Assistant components also rely on lxml: zeep, uscisstatus, pywemo, pytrafikverket, PyRMVtransport, pyquery, pymeteoclimatic, pykmtronic, ProgettiHWSW, openhomedevice, MechanicalSoup, fritzprofiles, caldav, afsapi

Tagging @balloob on this; just want to make sure the core team is aware of the lxml compatibility issue with libxml2 versions greater than 2.9.10. No issues right now, but updating the supported installation methods to a newer version of libxml2 may cause breakages. Just something to look out for.

esev commented 3 years ago

Hi @bobflem,

I went and filed a bug for the linuxserver folks (https://github.com/linuxserver/docker-homeassistant/issues/17). It looks like this issue was caused by a recent change on their end (4 days ago). I ran the python commands and verified ghcr.io/linuxserver/homeassistant:2021.7.4-ls31 (the prior version) works. I think everything will run with that version until they can downgrade their version of libxml2.

balloob commented 3 years ago

linuxserver/homeassistant is not an official image and is not a supported installation method.

Use our official container at https://github.com/home-assistant/core/pkgs/container/home-assistant

balloob commented 3 years ago

@esev thanks for finding this. Will look into this for our image but pretty sure it's not an issue for us as it hasn't been reported earlier. We already mark unsupported installation methods as unsupported but maybe there is a bug causing linuxserver container to be marked as supported. Will check that.

bobflem commented 3 years ago

Will start using the official image, thank you all for the help. I can't remember the exact reason why I chose the linuxserver image over the official image. I'll blame it on lack of experience with docker.

Hi @bobflem,

I went and filed a bug for the linuxserver folks (linuxserver/docker-homeassistant#17). It looks like this issue was caused by a recent change on their end (4 days ago). I ran the python commands and verified ghcr.io/linuxserver/homeassistant:2021.7.4-ls31 (the prior version) works. I think everything will run with that version until they can downgrade their version of libxml2.

I appreciate it, and I'm sure others using that image will as well.