How to use the pyhik.constants.XML_NAMESPACE function in pyHik

To help you get started, we’ve selected a few pyHik examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mezz64 / pyHik / pyhik / hikvision.py View on Github external
return None

        if response.status_code == requests.codes.unauthorized:
            _LOGGING.error('Authentication failed')
            return None

        if response.status_code != requests.codes.ok:
            # If we didn't receive 200, abort
            _LOGGING.debug('Unable to fetch device info.')
            return None

        try:
            tree = ET.fromstring(response.text)
            # Try to fetch namespace from XML
            nmsp = tree.tag.split('}')[0].strip('{')
            self.namespace = nmsp if nmsp.startswith('http') else XML_NAMESPACE
            _LOGGING.debug('Using Namespace: %s', self.namespace)

            for item in tree:
                tag = item.tag.split('}')[1]
                device_info[tag] = item.text

            return device_info

        except AttributeError as err:
            _LOGGING.error('Entire response: %s', response.text)
            _LOGGING.error('There was a problem: %s', err)
            return None