From a3a0496c4c7b8a094474994fe7457b6114395138 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Wed, 1 Aug 2018 15:39:09 -0400 Subject: [PATCH] fix response parse error add get_external_ip to txupnp-cli --- txupnp/__init__.py | 2 +- txupnp/cli.py | 7 +++++-- txupnp/gateway.py | 5 +++-- txupnp/scpd.py | 4 ++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/txupnp/__init__.py b/txupnp/__init__.py index d23d145..4105b7d 100644 --- a/txupnp/__init__.py +++ b/txupnp/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.0.1a1" +__version__ = "0.0.1a2" __name__ = "txupnp" __author__ = "Jack Robison" __maintainer__ = "Jack Robison" diff --git a/txupnp/cli.py b/txupnp/cli.py index 05ad231..b7473b4 100644 --- a/txupnp/cli.py +++ b/txupnp/cli.py @@ -15,7 +15,10 @@ def run_command(found, u, command): return if command == "debug_device": print(u.get_debug_info()) - if command == "list_mappings": + elif command == "get_external_ip": + ip = yield u.get_external_ip() + print(ip) + elif command == "list_mappings": redirects = yield u.get_redirects() print("found {} redirects".format(len(redirects))) for redirect in redirects: @@ -33,7 +36,7 @@ def main(): observer.start() log.setLevel(logging.DEBUG) command = args.command - if command not in ['debug_device', 'list_mappings']: + if command not in ['debug_device', 'list_mappings', 'get_external_ip']: return sys.exit(0) def show(err): diff --git a/txupnp/gateway.py b/txupnp/gateway.py index 88ded67..7dee8b6 100644 --- a/txupnp/gateway.py +++ b/txupnp/gateway.py @@ -32,7 +32,7 @@ class CaseInsensitive(object): except AttributeError as err: not_evaluated[k] = v if not_evaluated: - log.error("%s did not apply kwargs: %s", self.__class__.__name__, not_evaluated) + log.warning("%s did not apply kwargs: %s", self.__class__.__name__, not_evaluated) def _get_attr_name(self, case_insensitive): for k, v in self.__dict__.items(): @@ -87,6 +87,7 @@ class Device(CaseInsensitive): modelURL = None serialNumber = None udn = None + upc = None presentationURL = None iconList = None @@ -165,7 +166,7 @@ class Gateway(object): response = yield treq.get(self.location) self.xml_response = yield response.content() if not self.xml_response: - log.error("service sent an empty reply\n%s", self.debug_device()) + log.warning("service sent an empty reply\n%s", self.debug_device()) xml_dict = etree_to_dict(ElementTree.fromstring(self.xml_response)) schema_key = DEVICE root = ROOT diff --git a/txupnp/scpd.py b/txupnp/scpd.py index 6ccfb33..86d30e8 100644 --- a/txupnp/scpd.py +++ b/txupnp/scpd.py @@ -55,10 +55,10 @@ class _SCPDCommand(object): self.param_names = param_names self.returns = returns - def extract_body(self, xml_response, service_key=IP_SCHEMA): + def extract_body(self, xml_response): content_dict = etree_to_dict(ElementTree.fromstring(xml_response)) envelope = content_dict[ENVELOPE] - return flatten_keys(envelope[BODY], "{%s}" % service_key) + return flatten_keys(envelope[BODY], "{%s}" % self.service_id) def extract_response(self, body): body = handle_fault(body) # raises UPnPError if there is a fault