flyte / upnpclient

uPnP client library for Python 3.
MIT License
202 stars 37 forks source link

space before urn ' urn:microsoft-com:wmc-1-0' is not a valid URI #27

Open starkillerOG opened 4 years ago

starkillerOG commented 4 years ago

When I run:

import upnpclient as upnp
devices = upnp.discover()

I get these errors regarding my Marantz SR5008:

Error 'xmlns:ms: ' urn:microsoft-com:wmc-1-0' is not a valid URI, line 4, column 40 (<string>, line 4)' for http://192.168.1.xxx:8080/description.xml
Error 'xmlns:ms: ' urn:microsoft-com:wmc-1-0' is not a valid URI, line 4, column 40 (<string>, line 4)' for http://192.168.1.xxx:8080/description.xml
Error 'xmlns:ms: ' urn:microsoft-com:wmc-1-0' is not a valid URI, line 4, column 40 (<string>, line 4)' for http://192.168.1.xxx:8080/description.xml
Error 'xmlns:ms: ' urn:microsoft-com:wmc-1-0' is not a valid URI, line 4, column 40 (<string>, line 4)' for http://192.168.1.xxx:8080/description.xml
Error 'xmlns:ms: ' urn:microsoft-com:wmc-1-0' is not a valid URI, line 4, column 40 (<string>, line 4)' for http://192.168.1.xxx:8080/description.xml
Error 'xmlns:ms: ' urn:microsoft-com:wmc-1-0' is not a valid URI, line 4, column 40 (<string>, line 4)' for http://192.168.1.xxx:8080/description.xml

If I then run devices, I do get a list summing up some devices I have on my network but the Marantz is not in there, probably because of those errors mentioned above....

If I look at http://192.168.1.xxx:8080/description.xml I get the following XML:

<?xml version="1.0"?>
<root
  xmlns="urn:schemas-upnp-org:device-1-0"
  xmlns:ms=" urn:microsoft-com:wmc-1-0"
  xmlns:smsc="www.smsc.com"
  xmlns:qq="http://www.tencent.com"
  xmlns:pnpx="http://schemas.microsoft.com/windows/pnpx/2005/11"
  xmlns:df="http://schemas.microsoft.com/windows/2008/09/devicefoundation">
    <specVersion>
        <major>1</major>
        <minor>0</minor>
    </specVersion>
    <device>
        <dlna:X_DLNADOC xmlns:dlna="urn:schemas-dlna-org:device-1-0">DMR-1.50</dlna:X_DLNADOC>
        <pnpx:X_compatibleId>MS_DigitalMediaDeviceClass_DMR_V001
                </pnpx:X_compatibleId>
        <pnpx:X_deviceCategory>MediaDevices
                </pnpx:X_deviceCategory>
        <pnpx:X_hardwareId>VEN_0126&amp;DEV_0022&amp;REV_01
                </pnpx:X_hardwareId>
        <df:X_deviceCategory>Multimedia.DMR
                </df:X_deviceCategory>
        <deviceType>urn:schemas-upnp-org:device:MediaRenderer:1</deviceType>
        <friendlyName>?</friendlyName>
        <manufacturer>Marantz</manufacturer>
        <manufacturerURL>http://www.marantz.com</manufacturerURL>
        <modelDescription>AV SURROUND RECEIVER</modelDescription>
        <modelName>*SR5008</modelName>
        <modelNumber>5008</modelNumber>
        <modelURL>http://www.marantz.com</modelURL>
        <serialNumber>?</serialNumber>
        <UDN>?</UDN>
        <UPC>?</UPC>
        <iconList>
            <icon>
                <mimetype>image/jpeg</mimetype>
                <width>48</width>
                <height>48</height>
                <depth>24</depth>
                <url>/BCO_device_sm_icon.jpg</url>
            </icon>
            <icon>
                <mimetype>image/jpeg</mimetype>
                <width>120</width>
                <height>120</height>
                <depth>24</depth>
                <url>/BCO_device_lrg_icon.jpg</url>
            </icon>
            <icon>
                <mimetype>image/png</mimetype>
                <width>48</width>
                <height>48</height>
                <depth>24</depth>
                <url>/BCO_device_sm_icon.png</url>
            </icon>
            <icon>
                <mimetype>image/png</mimetype>
                <width>120</width>
                <height>120</height>
                <depth>24</depth>
                <url>/BCO_device_lrg_icon.png</url>
            </icon>
        </iconList>
        <serviceList>
            <service>
                <serviceType>urn:schemas-upnp-org:service:RenderingControl:1</serviceType>
                <serviceId>urn:upnp-org:serviceId:RenderingControl</serviceId>
                <SCPDURL>/RenderingControl/desc.xml</SCPDURL>
                <controlURL>/RenderingControl/ctrl</controlURL>
                <eventSubURL>/RenderingControl/evt</eventSubURL>
            </service>
            <service>
                <serviceType>urn:schemas-upnp-org:service:ConnectionManager:1</serviceType>
                <serviceId>urn:upnp-org:serviceId:ConnectionManager</serviceId>
                <SCPDURL>/ConnectionManager/desc.xml</SCPDURL>
                <controlURL>/ConnectionManager/ctrl</controlURL>
                <eventSubURL>/ConnectionManager/evt</eventSubURL>
            </service>
            <service>
                <serviceType>urn:schemas-upnp-org:service:AVTransport:1</serviceType>
                <serviceId>urn:upnp-org:serviceId:AVTransport</serviceId>
                <SCPDURL>/AVTransport/desc.xml</SCPDURL>
                <controlURL>/AVTransport/ctrl</controlURL>
                <eventSubURL>/AVTransport/evt</eventSubURL>
            </service>
        </serviceList>
        <presentationURL>http://192.168.1.xxx</presentationURL>
    </device>
</root>

Note that I replaced IP with xxx and some unimportant info with ?

I am pretty sure the problem is the space " " in the urn in line 4: xmlns:ms=" urn:microsoft-com:wmc-1-0"

Does anyone have an idea how to fix this?

FancyChaos commented 4 years ago

I believe this is a common issue with some AV receiver. I had the same one with my Denon. Maybe they are all using the same buggy UPnP stack.

A possible solution is to do the XML parsing in recovery mode if a problem like this is encountered, then it will still parse the file, even if the URI is malformed. The only downside is that this can (not must!) lead to undefined behavior later on. A flag that is set if an XML parsing error occurred could inform the programmer that undefined behavior can happen with this device. Maybe a bit wacky, but this is still way better than never interacting with the device in the first place.

I can do a PR for that in the next few days or even today if I find the time.