5kyc0d3r / upnpy

Lightweight UPnP client library for Python.
https://upnpy.readthedocs.io
MIT License
60 stars 18 forks source link

discover() fails with a different error #15

Open Udinanon opened 3 years ago

Udinanon commented 3 years ago

Trying to use it to discover upnp enabled devices, fails

upnpy.UPnP()
print(upnp.discover())
---------------------------------------------------------------------------
RemoteDisconnected                        Traceback (most recent call last)
<ipython-input-5-91ca0e1804f5> in <module>
      2 
      3 upnp = upnpy.UPnP()
----> 4 print(upnp.discover())
      5 

~/Python/Kivy/kivy_env/lib/python3.8/site-packages/upnpy/upnp/UPnP.py in discover(self, delay, **headers)
     31 
     32         discovered_devices = []
---> 33         for device in self.ssdp.m_search(discover_delay=delay, st='upnp:rootdevice', **headers):
     34             discovered_devices.append(device)
     35 

~/Python/Kivy/kivy_env/lib/python3.8/site-packages/upnpy/ssdp/SSDPRequest.py in m_search(self, discover_delay, st, **headers)
     48         self.socket.settimeout(discover_delay)
     49 
---> 50         devices = self._send_request(self._get_raw_request())
     51 
     52         for device in devices:

~/Python/Kivy/kivy_env/lib/python3.8/site-packages/upnpy/ssdp/SSDPRequest.py in _send_request(self, message)
     98 
     99                 response, addr = self.socket.recvfrom(65507)
--> 100                 device = SSDPDevice(addr, response.decode())
    101                 devices.append(device)
    102         except socket.timeout:

~/Python/Kivy/kivy_env/lib/python3.8/site-packages/upnpy/ssdp/SSDPDevice.py in __init__(self, address, response)
     85         self._get_type_request()
     86         self._get_base_url_request()
---> 87         self._get_services_request()
     88 
     89     def get_services(self):

~/Python/Kivy/kivy_env/lib/python3.8/site-packages/upnpy/ssdp/SSDPDevice.py in wrapper(device, *args, **kwargs)
     21         elif device.description == exceptions.NotAvailableError:
     22             return
---> 23         return func(device, *args, **kwargs)
     24     return wrapper
     25 

~/Python/Kivy/kivy_env/lib/python3.8/site-packages/upnpy/ssdp/SSDPDevice.py in wrapper(instance, *args, **kwargs)
     52         if instance.base_url is None:
     53             raise exceptions.NotRetrievedError('No base URL was retrieved for this device.')
---> 54         return func(instance, *args, **kwargs)
     55     return wrapper
     56 

~/Python/Kivy/kivy_env/lib/python3.8/site-packages/upnpy/ssdp/SSDPDevice.py in _get_services_request(self)
    174 
    175                 if parsed_service_id not in device_services.keys():
--> 176                     device_services[parsed_service_id] = self.Service(
    177                         service=service_string,
    178                         service_id=service_id,

~/Python/Kivy/kivy_env/lib/python3.8/site-packages/upnpy/ssdp/SSDPDevice.py in __init__(self, service, service_id, scpd_url, control_url, event_sub_url, base_url)
    267             self.state_variables = {}
    268 
--> 269             self._get_description_request()
    270             self._get_state_variables_request()
    271             self._get_actions_request()

~/Python/Kivy/kivy_env/lib/python3.8/site-packages/upnpy/ssdp/SSDPDevice.py in _get_description_request(self)
    299 
    300             try:
--> 301                 service_description = utils.make_http_request(self.scpd_url).read()
    302                 self.description = service_description.decode()
    303             except urllib.error.HTTPError as e:

~/Python/Kivy/kivy_env/lib/python3.8/site-packages/upnpy/utils.py in make_http_request(url, data, headers)
     79     # If data is provided the request method will automatically be set to POST by urllib
     80     request = urllib.request.Request(url, data=data, headers=headers)
---> 81     return urllib.request.urlopen(request)

/usr/lib/python3.8/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
    220     else:
    221         opener = _opener
--> 222     return opener.open(url, data, timeout)
    223 
    224 def install_opener(opener):

/usr/lib/python3.8/urllib/request.py in open(self, fullurl, data, timeout)
    523 
    524         sys.audit('urllib.Request', req.full_url, req.data, req.headers, req.get_method())
--> 525         response = self._open(req, data)
    526 
    527         # post-process response

/usr/lib/python3.8/urllib/request.py in _open(self, req, data)
    540 
    541         protocol = req.type
--> 542         result = self._call_chain(self.handle_open, protocol, protocol +
    543                                   '_open', req)
    544         if result:

/usr/lib/python3.8/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
    500         for handler in handlers:
    501             func = getattr(handler, meth_name)
--> 502             result = func(*args)
    503             if result is not None:
    504                 return result

/usr/lib/python3.8/urllib/request.py in http_open(self, req)
   1377 
   1378     def http_open(self, req):
-> 1379         return self.do_open(http.client.HTTPConnection, req)
   1380 
   1381     http_request = AbstractHTTPHandler.do_request_

/usr/lib/python3.8/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
   1352             except OSError as err: # timeout error
   1353                 raise URLError(err)
-> 1354             r = h.getresponse()
   1355         except:
   1356             h.close()

/usr/lib/python3.8/http/client.py in getresponse(self)
   1345         try:
   1346             try:
-> 1347                 response.begin()
   1348             except ConnectionError:
   1349                 self.close()

/usr/lib/python3.8/http/client.py in begin(self)
    305         # read until we get a non-100 response
    306         while True:
--> 307             version, status, reason = self._read_status()
    308             if status != CONTINUE:
    309                 break

/usr/lib/python3.8/http/client.py in _read_status(self)
    274             # Presumably, the server closed the connection before
    275             # sending a valid response.
--> 276             raise RemoteDisconnected("Remote end closed connection without"
    277                                      " response")
    278         try:

RemoteDisconnected: Remote end closed connection without response

Testing with other UPnP libraries doesn't gove any similar error, such as miniupnpc

alessiodam commented 1 year ago

same issue