Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sjthespian opened this issue May 20, 2020 · 0 comments
Open

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

sjthespian opened this issue May 20, 2020 · 0 comments

Comments

@sjthespian
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant