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

Handle connection errors when connecting to Apple TVs #5829

Merged
merged 3 commits into from Feb 9, 2017

Conversation

postlund
Copy link
Contributor

@postlund postlund commented Feb 9, 2017

Description:
Should fix these kinds of errors:

17-02-09 08:23:05 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/opt/home-assistant/virtualenv/lib/python3.4/site-packages/aiohttp/connector.py", line 666, in _create_direct_connection
    local_addr=self._local_addr)
  File "/usr/lib/python3.4/asyncio/base_events.py", line 570, in create_connection
    raise exceptions[0]
  File "/usr/lib/python3.4/asyncio/base_events.py", line 557, in create_connection
    yield from self.sock_connect(sock, address)
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
    value = future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/asyncio/selector_events.py", line 382, in _sock_connect_cb
    raise OSError(err, 'Connect call failed %s' % (address,))
ConnectionRefusedError: [Errno 111] Connect call failed ('10.0.10.22', 3689)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/home-assistant/virtualenv/lib/python3.4/site-packages/aiohttp/connector.py", line 350, in connect
    yield from self._create_connection(req)
  File "/opt/home-assistant/virtualenv/lib/python3.4/site-packages/aiohttp/connector.py", line 643, in _create_connection
    transport, proto = yield from self._create_direct_connection(req)
  File "/opt/home-assistant/virtualenv/lib/python3.4/site-packages/aiohttp/connector.py", line 689, in _create_direct_connection
    (req.host, req.port, exc.strerror)) from exc
aiohttp.errors.ClientOSError: [Errno 111] Can not connect to 10.0.10.22:3689 [Connect call failed ('10.0.10.22', 3689)]

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 233, in _step
    result = coro.throw(exc)
  File "/home/pi/home-assistant/homeassistant/helpers/entity_component.py", line 336, in _async_process_entity
    new_entity, self, update_before_add=update_before_add
  File "/home/pi/home-assistant/homeassistant/helpers/entity_component.py", line 181, in async_add_entity
    yield from entity.async_update()
  File "/home/pi/home-assistant/homeassistant/components/media_player/apple_tv.py", line 119, in async_update
    playing = yield from self._atv.metadata.playing()
  File "/opt/home-assistant/virtualenv/lib/python3.4/site-packages/pyatv/internal/apple_tv.py", line 240, in playing
    playstatus = yield from self.apple_tv.playstatus()
  File "/opt/home-assistant/virtualenv/lib/python3.4/site-packages/pyatv/daap.py", line 131, in get
    yield from self._assure_logged_in()
  File "/opt/home-assistant/virtualenv/lib/python3.4/site-packages/pyatv/daap.py", line 185, in _assure_logged_in
    yield from self.login()
  File "/opt/home-assistant/virtualenv/lib/python3.4/site-packages/pyatv/daap.py", line 119, in login
    resp = yield from self._do(_login_request)
  File "/opt/home-assistant/virtualenv/lib/python3.4/site-packages/pyatv/daap.py", line 145, in _do
    resp, status = yield from action()
  File "/opt/home-assistant/virtualenv/lib/python3.4/site-packages/pyatv/daap.py", line 50, in get_data
    url, headers=_DMAP_HEADERS, timeout=self._timeout)
  File "/opt/home-assistant/virtualenv/lib/python3.4/site-packages/aiohttp/client.py", line 577, in __iter__
    resp = yield from self._coro
  File "/opt/home-assistant/virtualenv/lib/python3.4/site-packages/aiohttp/client.py", line 215, in _request
    conn = yield from self._connector.connect(req)
  File "/opt/home-assistant/virtualenv/lib/python3.4/site-packages/aiohttp/connector.py", line 360, in connect
    .format(key, exc.strerror)) from exc
aiohttp.errors.ClientOSError: [Errno 111] Cannot connect to host 10.0.10.22:3689 ssl:False [Can not connect to 10.0.10.22:3689 [Connect call failed ('10.0.10.22', 3689)]]

Also bump pyatv to 0.1.2 which fixes a request leak.

Checklist:

If the code communicates with devices, web services, or third-party tools:

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.

Also bump pyatv to 0.1.2 which fixes a request leak.
@mention-bot
Copy link

@postlund, thanks for your PR! By analyzing the history of the files in this pull request, we identified @balloob, @fabaff and @rmkraus to be potential reviewers.

@andrey-git
Copy link
Contributor

Please fix lint errors

@balloob balloob added this to the 0.38 milestone Feb 9, 2017
import logging
import hashlib

import asyncio
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asyncio is a core module. Please import it on top

@pvizeli pvizeli merged commit ecbbb06 into home-assistant:dev Feb 9, 2017
@postlund postlund deleted the atv_connection_improvement branch February 9, 2017 21:33
balloob pushed a commit that referenced this pull request Feb 11, 2017
* Handle connection errors when connecting to Apple TVs

Also bump pyatv to 0.1.2 which fixes a request leak.

* Fix pylint error

* Fix import order
@balloob
Copy link
Member

balloob commented Feb 11, 2017

cherry-picked

@home-assistant home-assistant locked and limited conversation to collaborators May 19, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants