Skip to content
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

Fix for Pioneer sc-lx76 #182

Merged
merged 2 commits into from
Mar 7, 2016
Merged

Fix for Pioneer sc-lx76 #182

merged 2 commits into from
Mar 7, 2016

Conversation

hoojii
Copy link
Contributor

@hoojii hoojii commented Mar 7, 2016

Pioneer sc-lx76 (possibly others) gives unvalid description.xml. There is a space before urn. Replacing it to valid namespace fixes this and after this oneliner pulseaudio-dlna works.

masmu added a commit that referenced this pull request Mar 7, 2016
Fix for Pioneer sc-lx76
@masmu masmu merged commit e2fec9e into masmu:master Mar 7, 2016
@masmu
Copy link
Owner

masmu commented Mar 7, 2016

Thanks for that. I will modify it a little bit to make this more generic

@masmu
Copy link
Owner

masmu commented Mar 7, 2016

Well there is a real problem with that, so I had to remove your changes from master.

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

test = b'''<?xml version='1.0' encoding='utf-8'?>
<root configId="1" xmlns:ms=" urn:microsoft-com">
    <specVersion>
        <major>1</major>
        <minor>1</minor>
    </specVersion>
    <device>
        <manufacturer>Бланк</manufacturer>
    </device>
</root>'''


test2 = test.replace(
    'xmlns:ms=" urn:microsoft-com', 'xmlns:ms="urn:microsoft-com')

print(type(test))
print(type(test2))

print(test2)

Since we are using the unicode_literals module replace cannot work with bytes beyond ascii. So your commit breaks the xml parsing for every xml which contains non ascii chars.

@masmu
Copy link
Owner

masmu commented Mar 7, 2016

Solved. Could you please verify that my fix is working for you?

@thomas725
Copy link

thomas725 commented Jan 4, 2023

I'm trying to use your library together with a Pioneer VSX924 receiver, but see this exception in the log:

----------------------------------------
Exception occurred during processing of request from ('192.168.16.32', 5645)
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/pulseaudio_dlna/plugins/dlna/pyupnpv2/__init__.py", line 716, in from_xml
    xml_root = lxml.etree.fromstring(xml)
  File "src/lxml/etree.pyx", line 3257, in lxml.etree.fromstring
  File "src/lxml/parser.pxi", line 1916, in lxml.etree._parseMemoryDocument
  File "src/lxml/parser.pxi", line 1803, in lxml.etree._parseDoc
  File "src/lxml/parser.pxi", line 1144, in lxml.etree._BaseParser._parseDoc
  File "src/lxml/parser.pxi", line 618, in lxml.etree._ParserContext._handleParseResultDoc
  File "src/lxml/parser.pxi", line 728, in lxml.etree._handleParseResult
  File "src/lxml/parser.pxi", line 657, in lxml.etree._raiseParseError
  File "<string>", line 4
lxml.etree.XMLSyntaxError: xmlns:ms: ' urn:microsoft-com:wmc-1-0' is not a valid URI, line 4, column 40

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.10/socketserver.py", line 683, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/lib/python3.10/socketserver.py", line 360, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.10/socketserver.py", line 747, in __init__
    self.handle()
  File "/usr/lib/python3.10/site-packages/pulseaudio_dlna/plugins/dlna/ssdp/listener.py", line 48, in handle
    self.server.cb_on_device_alive(header)
  File "/usr/lib/python3.10/site-packages/pulseaudio_dlna/plugins/__init__.py", line 36, in wrapper
    device = f(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/pulseaudio_dlna/plugins/dlna/__init__.py", line 89, in _on_device_added
    return DLNAMediaRendererFactory.from_header(header)
  File "/usr/lib/python3.10/site-packages/pulseaudio_dlna/plugins/dlna/renderer.py", line 290, in from_header
    upnp_device = pyupnpv2.UpnpMediaRendererFactory.from_header(header)
  File "/usr/lib/python3.10/site-packages/pulseaudio_dlna/plugins/dlna/pyupnpv2/__init__.py", line 734, in from_header
    return cls.from_url(header['location'])
  File "/usr/lib/python3.10/site-packages/pulseaudio_dlna/plugins/dlna/pyupnpv2/__init__.py", line 651, in from_url
    return cls.from_xml(url, response.content)
  File "/usr/lib/python3.10/site-packages/pulseaudio_dlna/plugins/dlna/pyupnpv2/__init__.py", line 720, in from_xml
    xml = byto.repair_xml(xml)
  File "/usr/lib/python3.10/site-packages/pulseaudio_dlna/plugins/dlna/pyupnpv2/byto.py", line 38, in repair_xml
    bytes = re.sub(
  File "/usr/lib/python3.10/re.py", line 209, in sub
    return _compile(pattern, flags).sub(repl, string, count)
TypeError: cannot use a string pattern on a bytes-like object
----------------------------------------

This seems like a problem that should have been fixed by this pull request if I understood it correctly.
Also related: flyte/upnpclient#27

UPDATE: fixed the problem for me, by switching to https://aur.archlinux.org/packages/pulseaudio-dlna-cygn = https://github.com/Cygn/pulseaudio-dlna (from https://aur.archlinux.org/packages/pulseaudio-dlna = https://github.com/masmu/pulseaudio-dlna )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants