fix response parse error

add get_external_ip to txupnp-cli
This commit is contained in:
Jack Robison 2018-08-01 15:39:09 -04:00
parent 74180ceb2e
commit a3a0496c4c
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
4 changed files with 11 additions and 7 deletions

View file

@ -1,4 +1,4 @@
__version__ = "0.0.1a1" __version__ = "0.0.1a2"
__name__ = "txupnp" __name__ = "txupnp"
__author__ = "Jack Robison" __author__ = "Jack Robison"
__maintainer__ = "Jack Robison" __maintainer__ = "Jack Robison"

View file

@ -15,7 +15,10 @@ def run_command(found, u, command):
return return
if command == "debug_device": if command == "debug_device":
print(u.get_debug_info()) 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() redirects = yield u.get_redirects()
print("found {} redirects".format(len(redirects))) print("found {} redirects".format(len(redirects)))
for redirect in redirects: for redirect in redirects:
@ -33,7 +36,7 @@ def main():
observer.start() observer.start()
log.setLevel(logging.DEBUG) log.setLevel(logging.DEBUG)
command = args.command 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) return sys.exit(0)
def show(err): def show(err):

View file

@ -32,7 +32,7 @@ class CaseInsensitive(object):
except AttributeError as err: except AttributeError as err:
not_evaluated[k] = v not_evaluated[k] = v
if not_evaluated: 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): def _get_attr_name(self, case_insensitive):
for k, v in self.__dict__.items(): for k, v in self.__dict__.items():
@ -87,6 +87,7 @@ class Device(CaseInsensitive):
modelURL = None modelURL = None
serialNumber = None serialNumber = None
udn = None udn = None
upc = None
presentationURL = None presentationURL = None
iconList = None iconList = None
@ -165,7 +166,7 @@ class Gateway(object):
response = yield treq.get(self.location) response = yield treq.get(self.location)
self.xml_response = yield response.content() self.xml_response = yield response.content()
if not self.xml_response: 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)) xml_dict = etree_to_dict(ElementTree.fromstring(self.xml_response))
schema_key = DEVICE schema_key = DEVICE
root = ROOT root = ROOT

View file

@ -55,10 +55,10 @@ class _SCPDCommand(object):
self.param_names = param_names self.param_names = param_names
self.returns = returns 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)) content_dict = etree_to_dict(ElementTree.fromstring(xml_response))
envelope = content_dict[ENVELOPE] 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): def extract_response(self, body):
body = handle_fault(body) # raises UPnPError if there is a fault body = handle_fault(body) # raises UPnPError if there is a fault