-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
' urn:microsoft-com:wmc-1-0' leading space makes it an invalid URI #402
Comments
Does the solution in the ticket you linked work ? #363 (comment) |
Hello,
Error message:
I do not know Python well enough to fix the bug or to debug it more closely. |
You can try changing repair_xml in byto.py to look like this: def repair_xml(bytes):
def strip_namespaces(match):
return 'xmlns{prefix}="{content}"'.format(
prefix=match.group(1) if match.group(1) else '',
content=match.group(2).strip(),
)
bytes = re.sub(
b'xmlns(:.*?)?="(.*?)"', strip_namespaces, bytes,
flags=re.IGNORECASE)
return bytes
I don't have the equipment to test this, but the error goes away when I used the data you posted. |
Thanks for your quick help but with this change I now get the following error:
|
I thought something somewhere else might break, is there a stacktrace or is that the whole error? |
Sorry that I was a little lazy.
|
I have the same problem the code below fixes it... but is technically like opening the door with explosives :) because you lost the key. import re
def repair_xml(bytes):
def strip_namespaces(match):
return 'xmlns{prefix}="{content}"'.format(
prefix=match.group(1) if match.group(1) else '',
content=match.group(2).strip(),
)
st = bytes.decode('utf-8')
st = re.sub(
r'xmlns(:.*?)?="(.*?)"', strip_namespaces, st,
flags=re.IGNORECASE)
bytes = st.encode('utf-8')
return bytes |
Thank you, |
OK, I don't know what the project will accept as a PR, but I reckon to clean this up need to make the inner strip_namespace work with bytes, then we won't need the bytes->unicode->bytes dance. |
Can you add some debug for me in pulseaudio_dlna/plugins/dlna/pyupnpv2/init.py @classmethod
def from_xml(cls, url, xml): And add @classmethod
def from_xml(cls, url, xml):
print("xml: ", type(xml)) As I'm not sure if it's a string or bytes at that point yet. |
Trying things a little blindly, but this one should work if they are always bytes going in: def repair_xml(xml_bytes):
def strip_namespaces(match):
return b'xmlns%s="%s"' % (
match.group(1) if match.group(1) else b"",
match.group(2).strip(),
)
xml_bytes = re.sub(
b'xmlns(:.*?)?="(.*?)"', strip_namespaces, xml_bytes, flags=re.IGNORECASE
)
return xml_bytes |
Confirm Here is the debug output as desired.
I think it is bytes if I understand the last line correctly |
Nice, I'll turn it into a PR later. |
Thanks again for the fast and good help. |
Fix for masmu#402 I also ran the code through Black for formatting, renamed "bytes" to "xml_bytes" so we don't shadow the bytes builtin.
I had the same problem with my DENON DNP-F109 and get the Exception "XMLSyntaxError" in the modul „pyupnpv2“:
My current hack is patching the file "/usr/lib/python3.[?]/site-packages/pulseaudio_dlna/plugins/dlna/pyupnpv2/init.py" and add a simple replace(). I think this is perhaps a bit more straightforward and robust for this problem than "re.sub()" (Stackoveflow: "Use Python's string.replace vs re.sub"). But in the end, it's not really nice.
update syntax, thanks to stuaxo |
bytes has a xml = xml.replace(b' urn:microsoft-com', b'urn:microsoft-com') |
Though I guess this does a sort of similar thing to It would be nice to know if this is always meant to be bytes too, the bit that captures |
I don't know what all the kinds of bad XML can come through, but the advantage of the regex is it will catch xml with more than one space in it, but I don't know if that's ever an issue. |
I've been using this for a over a month and it's been fine, so I've made it a PR. |
Hello,
I think this is the same error as in #363 , but this time the affected hardware is the Marantz AV7702 receiver. Running pulseaudio-dlna --debug clearly shows the leading space in the URI :
Which, in turn, will raise :
I know that, where phyton2 simply threw a warning whenever a leading space was found in an URI, python3 now throws an error, hence the old py2-based pulseaudio-dlna would work perfectly with the Marantz, but now the same Maranzt is breaking the newer py3-based pulseaudio-dlna.
Is there any way of fixing this ? The AV7702 is a great DLNA-enabled AV receiver, and it is quite a pity not being able to use it with pulseaudio-dlna.
thanks,
The text was updated successfully, but these errors were encountered: