How to use the fritzconnection.core.exceptions.FritzConnectionException function in fritzconnection

To help you get started, we’ve selected a few fritzconnection 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 kbr / fritzconnection / fritzconnection / core / soaper.py View on Github external
the error code and description if available
    """
    parts = []
    error_code = None
    try:
        root = etree.fromstring(response.content)
    except etree.ParseError:
        # May fail in case it's html instead of xml.
        # Can happen on wrong authentication.
        # That means it is not an error reported from executing
        # some service in the box, but rather not allowed to
        # access the box at all.
        # Whatever it is, report it here:
        detail = re.sub(r'<.*?>', '', response.text)
        msg = f'Unable to perform operation. {detail}'
        raise FritzConnectionException(msg)
    detail = root.find('.//detail')
    children = detail.iter()
    next(children) # skip detail itself
    for node in children:
        tag = localname(node)
        text = node.text.strip()
        if tag == "errorCode":
            error_code = text
        parts.append(f'{tag}: {text}')
    message = '\n'.join(parts)
    # try except:KeyError not possible,
    # because one of the raised Exceptions may inherit from KeyError.
    exception = FRITZ_ERRORS.get(error_code, FritzConnectionException)
    raise exception(message)
github kbr / fritzconnection / fritzconnection / core / utils.py View on Github external
def handle_response(response):
        ct = response.headers.get("Content-type")
        if ct == "text/html":
            message = f"Unable to retrieve resource '{url}' from the device."
            raise FritzConnectionException(message)
        return response.text
github kbr / fritzconnection / fritzconnection / core / soaper.py View on Github external
detail = re.sub(r'<.*?>', '', response.text)
        msg = f'Unable to perform operation. {detail}'
        raise FritzConnectionException(msg)
    detail = root.find('.//detail')
    children = detail.iter()
    next(children) # skip detail itself
    for node in children:
        tag = localname(node)
        text = node.text.strip()
        if tag == "errorCode":
            error_code = text
        parts.append(f'{tag}: {text}')
    message = '\n'.join(parts)
    # try except:KeyError not possible,
    # because one of the raised Exceptions may inherit from KeyError.
    exception = FRITZ_ERRORS.get(error_code, FritzConnectionException)
    raise exception(message)
github kbr / fritzconnection / fritzconnection / core / fritzconnection.py View on Github external
# store as instance attributes for use by library modules
        self.address = address
        self.session = session
        self.timeout = timeout
        self.port = port

        self.soaper = Soaper(
            address, port, user, password, timeout=timeout, session=session
        )
        self.device_manager = DeviceManager(timeout=timeout, session=session)

        for description in FRITZ_DESCRIPTIONS:
            source = f'{address}:{port}/{description}'
            try:
                self.device_manager.add_description(source)
            except FritzConnectionException:
                # resource not available:
                # this can happen on devices not providing
                # an igddesc-file.
                # ignore this
                pass

        self.device_manager.scan()
        self.device_manager.load_service_descriptions(address, port)
github kbr / fritzconnection / fritzconnection / core / exceptions.py View on Github external
'FritzServiceError',
]


class FritzConnectionException(Exception):
    """Base Exception for communication errors with the Fritz!Box"""


class ActionError(FritzConnectionException):
    """
    Exception raised by calling nonexisting actions.
    Legathy Exception. Use FritzActionError instead.
    """


class ServiceError(FritzConnectionException):
    """
    Exception raised by calling nonexisting services.
    Legathy Exception. Use FritzServiceError instead.
    """


class FritzServiceError(ServiceError):
    """Exception raised by calling nonexisting services."""


class FritzActionError(ActionError):
    """Exception raised by calling nonexisting actions."""


class FritzArgumentError(FritzConnectionException):
    """Exception raised by invalid arguments."""
github mammuth / ha-fritzbox-tools / custom_components / fritzbox_tools / __init__.py View on Github external
def is_ok(self):
        # TODO for future: do more of the async_setup_entry checks right here

        from fritzconnection.core.exceptions import FritzConnectionException

        try:
            _ = self.connection.call_action(
                "Layer3Forwarding:1", "GetDefaultConnectionService"
            )["NewDefaultConnectionService"]
            return True, ""
        except FritzConnectionException:
            return False, "connection_error"
github kbr / fritzconnection / fritzconnection / core / exceptions.py View on Github external
class FritzArgumentStringToLongError(FritzArgumentValueError):
    """
    Exception raised by arguments with invalid string length for the
    string being to long. Inherits from the more generic
    FritzArgumentValueError.
    """


class FritzArgumentCharacterError(FritzArgumentValueError):
    """
    Exception raised by arguments with invalid characters.
    Inherits from the more generic FritzArgumentValueError.
    """


class FritzInternalError(FritzConnectionException):
    """Exception raised by panic in the box."""


class FritzActionFailedError(FritzInternalError):
    """
    Exception raised by the box unable to execute the action properly.
    Inherits from the more generic FritzInternalError.
    """


class FritzOutOfMemoryError(FritzInternalError):
    """
    Exception raised by memory shortage of the box.
    Inherits from the more generic FritzInternalError.
    """
github kbr / fritzconnection / fritzconnection / core / exceptions.py View on Github external
'FritzArgumentStringToShortError',
    'FritzArgumentValueError',
    'FritzArrayIndexError',
    'FritzInternalError',
    'FritzLookUpError',
    'FritzOutOfMemoryError',
    'FritzSecurityError',
    'FritzServiceError',
]


class FritzConnectionException(Exception):
    """Base Exception for communication errors with the Fritz!Box"""


class ActionError(FritzConnectionException):
    """
    Exception raised by calling nonexisting actions.
    Legathy Exception. Use FritzActionError instead.
    """


class ServiceError(FritzConnectionException):
    """
    Exception raised by calling nonexisting services.
    Legathy Exception. Use FritzServiceError instead.
    """


class FritzServiceError(ServiceError):
    """Exception raised by calling nonexisting services."""
github kbr / fritzconnection / fritzconnection / core / exceptions.py View on Github external
class ServiceError(FritzConnectionException):
    """
    Exception raised by calling nonexisting services.
    Legathy Exception. Use FritzServiceError instead.
    """


class FritzServiceError(ServiceError):
    """Exception raised by calling nonexisting services."""


class FritzActionError(ActionError):
    """Exception raised by calling nonexisting actions."""


class FritzArgumentError(FritzConnectionException):
    """Exception raised by invalid arguments."""


class FritzArgumentValueError(FritzArgumentError):
    """
    Exception raised by arguments with invalid values.
    Inherits from the more generic FritzArgumentError.
    """


class FritzArgumentStringToShortError(FritzArgumentValueError):
    """
    Exception raised by arguments with invalid string length for the
    string being to short. Inherits from the more generic
    FritzArgumentValueError.
    """