Skip to content

dlipower.py doesn't throw exception on DNS failure #48

@sjthespian

Description

@sjthespian

I'm using the digitialloggers integration with Home Assistant (https://www.home-assistant.io/integrations/digitalloggers/), and it looks like it doesn't throw an exception on DNS lookup failures. The exception at the following line only catches exceptions from the requests module, it won't catch ConnectionError exceptions:
https://github.com/dwighthubbard/python-dlipower/blob/master/dlipower/dlipower.py#L416

There are several exceptions in requests that are not subclasses of RequestException: https://2.python-requests.org/en/v3.0.0/_modules/requests/exceptions/

When using dqlipower.py under Home Assistant (which should be based on 0.7.165), it is throwing the following error:

2020-05-20 13:43:48 ERROR (MainThread) [homeassistant.components.switch] Error w
hile setting up digitalloggers platform for switch
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 1
78, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/digitalloggers/switch.py
", line 61, in setup_platform
    if not power_switch.verify():
  File "/usr/local/lib/python3.7/site-packages/dlipower/dlipower.py", line 352, in verify
    if self.geturl():
  File "/usr/local/lib/python3.7/site-packages/dlipower/dlipower.py", line 373, in geturl
    logger.debug('Response code: %s', request.status_code)
AttributeError: 'NoneType' object has no attribute 'status_code

If I use the IP address instead of the hostname, that error goes away.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions