upnpy icon indicating copy to clipboard operation
upnpy copied to clipboard

Uncaught Exception in discover()

Open tnjohnston opened this issue 4 years ago • 3 comments

I was unable to use this library on my network due to the following uncaught exception when calling the discover() method.

Python 3.10.2 (v3.10.2:a58ebcc701, Jan 13 2022, 14:50:16) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin Type "help", "copyright", "credits" or "license" for more information.

import upnpy upnp = upnpy.UPnP() devices = upnp.discover()

Traceback (most recent call last): File "", line 1, in File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/upnpy/upnp/UPnP.py", line 33, in discover for device in self.ssdp.m_search(discover_delay=delay, st='upnp:rootdevice', **headers): File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/upnpy/ssdp/SSDPRequest.py", line 50, in m_search devices = self._send_request(self._get_raw_request()) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/upnpy/ssdp/SSDPRequest.py", line 100, in _send_request device = SSDPDevice(addr, response.decode()) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/upnpy/ssdp/SSDPDevice.py", line 83, in init self._get_description_request(utils.parse_http_header(response, 'Location')) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/upnpy/ssdp/SSDPDevice.py", line 117, in _get_description_request device_description = utils.make_http_request(url).read() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/upnpy/utils.py", line 81, in make_http_request return urllib.request.urlopen(request) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 216, in urlopen return opener.open(url, data, timeout) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 519, in open response = self._open(req, data) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 536, in _open result = self._call_chain(self.handle_open, protocol, protocol + File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 496, in _call_chain result = func(*args) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 1377, in http_open return self.do_open(http.client.HTTPConnection, req) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 1352, in do_open r = h.getresponse() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1374, in getresponse response.begin() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 318, in begin version, status, reason = self._read_status() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 279, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/socket.py", line 705, in readinto return self._sock.recv_into(b) ConnectionResetError: [Errno 54] Connection reset by peer

tnjohnston avatar Feb 03 '22 17:02 tnjohnston

With a very simple program:

#!/usr/bin/python3

import upnpy

upnp = upnpy.UPnP()
devices = upnp.discover()

I too get an exception:

Traceback (most recent call last):
  File "/home/pi/backend/./upnp_debug.py", line 6, in <module>
    devices = upnp.discover()
  File "/home/pi/.local/lib/python3.9/site-packages/upnpy/upnp/UPnP.py", line 33, in discover
    for device in self.ssdp.m_search(discover_delay=delay, st='upnp:rootdevice', **headers):
  File "/home/pi/.local/lib/python3.9/site-packages/upnpy/ssdp/SSDPRequest.py", line 50, in m_search
    devices = self._send_request(self._get_raw_request())
  File "/home/pi/.local/lib/python3.9/site-packages/upnpy/ssdp/SSDPRequest.py", line 100, in _send_request
    device = SSDPDevice(addr, response.decode())
  File "/home/pi/.local/lib/python3.9/site-packages/upnpy/ssdp/SSDPDevice.py", line 87, in __init__
    self._get_services_request()
  File "/home/pi/.local/lib/python3.9/site-packages/upnpy/ssdp/SSDPDevice.py", line 23, in wrapper
    return func(device, *args, **kwargs)
  File "/home/pi/.local/lib/python3.9/site-packages/upnpy/ssdp/SSDPDevice.py", line 54, in wrapper
    return func(instance, *args, **kwargs)
  File "/home/pi/.local/lib/python3.9/site-packages/upnpy/ssdp/SSDPDevice.py", line 171, in _get_services_request
    event_sub_url = service.getElementsByTagName('eventSubURL')[0].firstChild.nodeValue
AttributeError: 'NoneType' object has no attribute 'nodeValue'

(not the same, but much easier to read)

coofercat avatar Feb 13 '22 17:02 coofercat

test.py is the 2nd example on the home page:

import test Traceback (most recent call last): File "", line 1, in File "C:\python\2dshooter\network\test.py", line 7, in devices = upnp.discover() File "C:\Projects\Kraken\venv\lib\site-packages\upnpy\upnp\UPnP.py", line 33, in discover for device in self.ssdp.m_search(discover_delay=delay, st='upnp:rootdevice', **headers): File "C:\Projects\Kraken\venv\lib\site-packages\upnpy\ssdp\SSDPRequest.py", line 50, in m_search devices = self._send_request(self._get_raw_request()) File "C:\Projects\Kraken\venv\lib\site-packages\upnpy\ssdp\SSDPRequest.py", line 100, in _send_request device = SSDPDevice(addr, response.decode()) File "C:\Projects\Kraken\venv\lib\site-packages\upnpy\ssdp\SSDPDevice.py", line 87, in init self._get_services_request() File "C:\Projects\Kraken\venv\lib\site-packages\upnpy\ssdp\SSDPDevice.py", line 23, in wrapper return func(device, *args, **kwargs) File "C:\Projects\Kraken\venv\lib\site-packages\upnpy\ssdp\SSDPDevice.py", line 54, in wrapper return func(instance, *args, **kwargs) File "C:\Projects\Kraken\venv\lib\site-packages\upnpy\ssdp\SSDPDevice.py", line 170, in _get_services_request control_url = service.getElementsByTagName('controlURL')[0].firstChild.nodeValue AttributeError: 'NoneType' object has no attribute 'nodeValue'

mark-pippin avatar May 15 '22 08:05 mark-pippin

Fix in PR: https://github.com/5kyc0d3r/upnpy/pull/19

for others, if that PR has not been merged, you may see here if you wish: https://github.com/Velas2/upnpy-bugfix/tree/frozen-bug-fix

mark-pippin avatar May 15 '22 09:05 mark-pippin