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

get_attached_devices fails due to & in device name #75

Open
on-kage opened this issue Sep 7, 2019 · 1 comment
Open

get_attached_devices fails due to & in device name #75

on-kage opened this issue Sep 7, 2019 · 1 comment

Comments

@on-kage
Copy link

on-kage commented Sep 7, 2019

I have an AT&T device that registers with the & in the name. This causes get_attached_devices to fail with the error:
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 9, column 407

If I remove this device from the network, then get_attached_devices returns just fine. The actual device name is "AT&T TV - C71LB8CR111646"

@mhelsley
Copy link

That looks a lot like a bug in the Netgear router software itself -- not an issue with pynetgear -- where it has failed to properly transform the name of your device into an XML-safe string for output via Netgear's SOAP API. It should be replacing "&" with "&"

The way to find out would be simple. Use this script, supplying your password, to cause pynetgear to execute from the command line. But before you execute it, go into the pynetgear module that's been installed and add print(response.text) before the _find_node() call in get_attached_devices(). It will show you the "raw" text you got back before the XML parser tries to do anything with it. Do you see "AT&T" in the raw text? If so then it's a big in the router. Otherwise it's something to do with the XML parsing code (and in that case it'd be good to see the output).

#!/usr/bin/python3

if name == 'main':
import sys
from pynetgear import Netgear

device_attrs = [
    "name",
    "ip",
    "type",
    "signal",
    "link_rate",
    "allow_or_block",
    "device_type",
    "device_model",
    "ssid",
    "conn_ap_mac"
]

if len(sys.argv) < 2:
    print("Password required as command line argument")
    sys.exit(2)
netgear = Netgear(password=sys.argv[1])
try:
    for device in netgear.get_attached_devices():
        print(f"{device.mac}")
        for var in device_attrs:
            value = device.__getattribute__(var)
            if value is None:
                continue
            kind = str(type(value))
            print(f"\t{var}: {value} ({kind})")
except TypeError:
    print("API inaccessible")

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

No branches or pull requests

2 participants