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

example gives error #7

Open
MaxCarritt opened this issue Jul 8, 2020 · 6 comments
Open

example gives error #7

MaxCarritt opened this issue Jul 8, 2020 · 6 comments
Labels
bug Something isn't working

Comments

@MaxCarritt
Copy link

MaxCarritt commented Jul 8, 2020

Hi, I installed upnpy, and ran the script from you example:

import upnpy

upnp = upnpy.UPnP()

# Discover UPnP devices on the network
# Returns a list of devices e.g.: [Device <Broadcom ADSL Router>]
devices = upnp.discover()

# Select the IGD
# alternatively you can select the device directly from the list
# device = devices[0]
device = upnp.get_igd()

and on line 7 I get the following error:

Traceback (most recent call last):
  File "C:\Users\VMUser\Documents\upnpy test.py", line 7, in <module>
    devices = upnp.discover()
  File "C:\Users\VMUser\AppData\Local\Programs\Python\Python38\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:\Users\VMUser\AppData\Local\Programs\Python\Python38\lib\site-packages\upnpy\ssdp\SSDPRequest.py", line 50, in m_search
    devices = self._send_request(self._get_raw_request())
  File "C:\Users\VMUser\AppData\Local\Programs\Python\Python38\lib\site-packages\upnpy\ssdp\SSDPRequest.py", line 100, in _send_request
    device = SSDPDevice(addr, response.decode())
  File "C:\Users\VMUser\AppData\Local\Programs\Python\Python38\lib\site-packages\upnpy\ssdp\SSDPDevice.py", line 87, in __init__
    self._get_services_request()
  File "C:\Users\VMUser\AppData\Local\Programs\Python\Python38\lib\site-packages\upnpy\ssdp\SSDPDevice.py", line 23, in wrapper
    return func(device, *args, **kwargs)
  File "C:\Users\VMUser\AppData\Local\Programs\Python\Python38\lib\site-packages\upnpy\ssdp\SSDPDevice.py", line 54, in wrapper
    return func(instance, *args, **kwargs)
  File "C:\Users\VMUser\AppData\Local\Programs\Python\Python38\lib\site-packages\upnpy\ssdp\SSDPDevice.py", line 173, in _get_services_request
    device_services[parsed_service_id] = self.Service(
  File "C:\Users\VMUser\AppData\Local\Programs\Python\Python38\lib\site-packages\upnpy\ssdp\SSDPDevice.py", line 258, in __init__
    self._get_state_variables_request()
  File "C:\Users\VMUser\AppData\Local\Programs\Python\Python38\lib\site-packages\upnpy\ssdp\SSDPDevice.py", line 39, in wrapper
    return func(service, *args, **kwargs)
  File "C:\Users\VMUser\AppData\Local\Programs\Python\Python38\lib\site-packages\upnpy\ssdp\SSDPDevice.py", line 363, in _get_state_variables_request
    root = minidom.parseString(service_description)
  File "C:\Users\VMUser\AppData\Local\Programs\Python\Python38\lib\xml\dom\minidom.py", line 1969, in parseString
    return expatbuilder.parseString(string)
  File "C:\Users\VMUser\AppData\Local\Programs\Python\Python38\lib\xml\dom\expatbuilder.py", line 925, in parseString
    return builder.parseString(string)
  File "C:\Users\VMUser\AppData\Local\Programs\Python\Python38\lib\xml\dom\expatbuilder.py", line 223, in parseString
    parser.Parse(string, True)
xml.parsers.expat.ExpatError: no element found: line 1, column 0
[Finished in 0.2s with exit code 1]
[shell_cmd: python -u "C:\Users\VMUser\Documents\upnpy test.py"]
@nashant
Copy link

nashant commented Jul 12, 2020

I get a different error but another issue with upnp.discover():

>>> upnp.discover()
Traceback (most recent call last):
  File "/usr/lib/python3.6/http/client.py", line 897, in _get_hostport
    port = int(host[i+1:])
ValueError: invalid literal for int() with base 10: '49152wps_scpd.xml'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/upnpy/upnp/UPnP.py", line 33, in discover
    for device in self.ssdp.m_search(discover_delay=delay, st='upnp:rootdevice', **headers):
  File "/usr/local/lib/python3.6/dist-packages/upnpy/ssdp/SSDPRequest.py", line 50, in m_search
    devices = self._send_request(self._get_raw_request())
  File "/usr/local/lib/python3.6/dist-packages/upnpy/ssdp/SSDPRequest.py", line 100, in _send_request
    device = SSDPDevice(addr, response.decode())
  File "/usr/local/lib/python3.6/dist-packages/upnpy/ssdp/SSDPDevice.py", line 87, in __init__
    self._get_services_request()
  File "/usr/local/lib/python3.6/dist-packages/upnpy/ssdp/SSDPDevice.py", line 23, in wrapper
    return func(device, *args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/upnpy/ssdp/SSDPDevice.py", line 54, in wrapper
    return func(instance, *args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/upnpy/ssdp/SSDPDevice.py", line 179, in _get_services_request
    base_url=base_url
  File "/usr/local/lib/python3.6/dist-packages/upnpy/ssdp/SSDPDevice.py", line 257, in __init__
    self._get_description_request()
  File "/usr/local/lib/python3.6/dist-packages/upnpy/ssdp/SSDPDevice.py", line 289, in _get_description_request
    service_description = utils.make_http_request(self.base_url + self.scpd_url).read()
  File "/usr/local/lib/python3.6/dist-packages/upnpy/utils.py", line 81, in make_http_request
    return urllib.request.urlopen(request)
  File "/usr/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.6/urllib/request.py", line 526, in open
    response = self._open(req, data)
  File "/usr/lib/python3.6/urllib/request.py", line 544, in _open
    '_open', req)
  File "/usr/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.6/urllib/request.py", line 1353, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/usr/lib/python3.6/urllib/request.py", line 1293, in do_open
    h = http_class(host, timeout=req.timeout, **http_conn_args)
  File "/usr/lib/python3.6/http/client.py", line 859, in __init__
    (self.host, self.port) = self._get_hostport(host, port)
  File "/usr/lib/python3.6/http/client.py", line 902, in _get_hostport
    raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
http.client.InvalidURL: nonnumeric port: '49152wps_scpd.xml'

@Schyrsivochter
Copy link

Confirming this happens on Linux, too:

Python 3.8.5 (default, Jul 28 2020, 12:59:40) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import upnpy
>>> upnp = upnpy.UPnP()
>>> upnp.discover()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/dist-packages/upnpy/upnp/UPnP.py", line 33, in discover
    for device in self.ssdp.m_search(discover_delay=delay, st='upnp:rootdevice', **headers):
  File "/usr/local/lib/python3.8/dist-packages/upnpy/ssdp/SSDPRequest.py", line 50, in m_search
    devices = self._send_request(self._get_raw_request())
  File "/usr/local/lib/python3.8/dist-packages/upnpy/ssdp/SSDPRequest.py", line 100, in _send_request
    device = SSDPDevice(addr, response.decode())
  File "/usr/local/lib/python3.8/dist-packages/upnpy/ssdp/SSDPDevice.py", line 87, in __init__
    self._get_services_request()
  File "/usr/local/lib/python3.8/dist-packages/upnpy/ssdp/SSDPDevice.py", line 23, in wrapper
    return func(device, *args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/upnpy/ssdp/SSDPDevice.py", line 54, in wrapper
    return func(instance, *args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/upnpy/ssdp/SSDPDevice.py", line 176, in _get_services_request
    device_services[parsed_service_id] = self.Service(
  File "/usr/local/lib/python3.8/dist-packages/upnpy/ssdp/SSDPDevice.py", line 270, in __init__
    self._get_state_variables_request()
  File "/usr/local/lib/python3.8/dist-packages/upnpy/ssdp/SSDPDevice.py", line 39, in wrapper
    return func(service, *args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/upnpy/ssdp/SSDPDevice.py", line 375, in _get_state_variables_request
    root = minidom.parseString(service_description)
  File "/usr/lib/python3.8/xml/dom/minidom.py", line 1969, in parseString
    return expatbuilder.parseString(string)
  File "/usr/lib/python3.8/xml/dom/expatbuilder.py", line 925, in parseString
    return builder.parseString(string)
  File "/usr/lib/python3.8/xml/dom/expatbuilder.py", line 223, in parseString
    parser.Parse(string, True)
xml.parsers.expat.ExpatError: no element found: line 1, column 0

@heliomcp
Copy link

Got another error "(invalid token)":

Python 3.7.2 (default, Jan 17 2019, 23:30:57)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import upnpy
>>> upnp = upnpy.UPnP()
>>> devices = upnp.discover()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/media/upnpy/upnpy/upnp/UPnP.py", line 33, in discover
    for device in self.ssdp.m_search(discover_delay=delay, st='upnp:rootdevice', **headers):
  File "/media/upnpy/upnpy/ssdp/SSDPRequest.py", line 50, in m_search
    devices = self._send_request(self._get_raw_request())
  File "/media/upnpy/upnpy/ssdp/SSDPRequest.py", line 100, in _send_request
    device = SSDPDevice(addr, response.decode())
  File "/media/upnpy/upnpy/ssdp/SSDPDevice.py", line 84, in __init__
    self._get_friendly_name_request()
  File "/media/upnpy/upnpy/ssdp/SSDPDevice.py", line 23, in wrapper
    return func(device, *args, **kwargs)
  File "/media/upnpy/upnpy/ssdp/SSDPDevice.py", line 127, in _get_friendly_name_request
    root = minidom.parseString(self.description)
  File "/usr/local/lib/python3.7/xml/dom/minidom.py", line 1968, in parseString
    return expatbuilder.parseString(string)
  File "/usr/local/lib/python3.7/xml/dom/expatbuilder.py", line 925, in parseString
    return builder.parseString(string)
  File "/usr/local/lib/python3.7/xml/dom/expatbuilder.py", line 223, in parseString
    parser.Parse(string, True)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, column 6
>>>

@mkluge
Copy link

mkluge commented Jan 16, 2021

Same error here on Linux Mint 20.1.

@virtadpt
Copy link

I was able to recreate all of these errors. Arch Linux (20210819). Python v3.9.6 UPnPy v1.1.8 installed with Pip.

@nashant
Copy link

nashant commented Mar 26, 2022

Raising this from the dead, you can search for just IGDs with upnp.discover(ST='urn:schemas-upnp-org:device:InternetGatewayDevice:1')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants