Apple TV - apple_tv:failed to login

@postlund I’ve been running the fix for a few hours now, and so far it’s working wonderfully!

I’ve switched between different apps (plex, netflix, youtube, hulu) and the component recognizes what’s playing for each. Also powered everything off, and back on, and started playing something… the component didn’t miss a beat, and updated the UI without issue.

I’d call the fix a success, and get it added! Thank you for all your hard work, it’s been a few months but I think this may have fixed it!

Will continue to test, and report back any issues I find.

Sounds good! :+1: Did you get any “400 error” in the log? If that’s not present you haven’t triggered the use case, so I want to confirm that before doing a new release.

I’ve made some changes to pyatv and implemented a real fix. This should solve re-login issues altogether and also not expose them to the user in case everything sorts itself out. I’ll see if I can make a release of it and update Home Assistant.

Here is a PR that hopefully fixes this issue once and for all: https://github.com/home-assistant/home-assistant/pull/11104

2 Likes

Thanks @postlund once it’s merged and released, I’ll get it updated and test everything out. Unless you’d like me to merge your changes now, and test everything?

If you have the time and possibility to test it out, it would be appreciated :blush:

Thank you for your continued time and attention @postlund, it’s massively appreciated.

My ATV4 is working at the moment. It dropped out for a while but restarting Home Assistant picked it back up again.

I’m looking forward to see what the new pyatv update brings!

1 Like

The PR was merged yesteryday, so it’s on dev now.

1 Like

Just upgraded lastnight (which included your PR), and the component has been working wonderfully ever since! I’ll update this post if anything changes, but for now I think we can finally put this :poop: to :sleeping_bed:!

1 Like

Awesome! I hope it keeps working!

Chiming in to echo @xstrex, no more problems here!

1 Like

@postlund Looks like we’ve got another related issue in the logs, same message in the UI as before "Establishing a connection… "

2017-12-26 19:24:09 WARNING (MainThread) [pyatv.tag_definitions] Unknown data: b'103'
2017-12-26 19:24:09 WARNING (MainThread) [pyatv.tag_definitions] Unknown data: b'103'
2017-12-26 19:24:09 WARNING (MainThread) [homeassistant.components.media_player.apple_tv] A <class 'pyatv.exceptions.AuthenticationError'> error occurred: failed to login: 503
2017-12-26 19:24:19 WARNING (MainThread) [pyatv.tag_definitions] Unknown data: b'103'
2017-12-26 19:24:19 WARNING (MainThread) [pyatv.tag_definitions] Unknown data: b'103'
2017-12-26 19:24:20 WARNING (MainThread) [homeassistant.components.media_player.apple_tv] A <class 'pyatv.exceptions.AuthenticationError'> error occurred: failed to login: 503
2017-12-26 19:24:30 WARNING (MainThread) [pyatv.tag_definitions] Unknown data: b'103'
2017-12-26 19:24:30 WARNING (MainThread) [pyatv.tag_definitions] Unknown data: b'103'
2017-12-26 19:24:30 WARNING (MainThread) [homeassistant.components.media_player.apple_tv] A <class 'pyatv.exceptions.AuthenticationError'> error occurred: failed to login: 503
2017-12-26 19:24:40 WARNING (MainThread) [pyatv.tag_definitions] Unknown data: b'103'
2017-12-26 19:24:40 WARNING (MainThread) [pyatv.tag_definitions] Unknown data: b'103'
2017-12-26 19:24:40 WARNING (MainThread) [homeassistant.components.media_player.apple_tv] A <class 'pyatv.exceptions.AuthenticationError'> error occurred: failed to login: 503
2017-12-26 19:24:50 WARNING (MainThread) [pyatv.tag_definitions] Unknown data: b'103'
2017-12-26 19:24:50 WARNING (MainThread) [pyatv.tag_definitions] Unknown data: b'103'
2017-12-26 19:24:50 WARNING (MainThread) [homeassistant.components.media_player.apple_tv] A <class 'pyatv.exceptions.AuthenticationError'> error occurred: failed to login: 503
2017-12-26 19:25:00 WARNING (MainThread) [pyatv.tag_definitions] Unknown data: b'103'
2017-12-26 19:25:00 WARNING (MainThread) [pyatv.tag_definitions] Unknown data: b'103'
2017-12-26 19:25:00 WARNING (MainThread) [homeassistant.components.media_player.apple_tv] A <class 'pyatv.exceptions.AuthenticationError'> error occurred: failed to login: 503

Do you know when this happen and can you easily reproduce it?

I noticed it yesterday afternoon, I’ll get the logs showing exactly when it happened. Then I’ll try and reproduce it.

1 Like

Here’s the first occurrence of the error:

2017-12-26 18:12:27 WARNING (MainThread) [pyatv.tag_definitions] Unknown data: b’103’
2017-12-26 18:12:27 WARNING (MainThread) [pyatv.tag_definitions] Unknown data: b’103’
2017-12-26 18:12:27 WARNING (MainThread) [homeassistant.components.media_player.apple_tv] A <class ‘pyatv.exceptions.AuthenticationError’> error occurred: failed to login: 503

Nothing relevant prior…

If I turn the media_player component ‘off’ in the frontend, then back ‘on’, I see this in the log:

2017-12-27 16:04:19 WARNING (MainThread) [pyatv.tag_definitions] Unknown data: b’103’
2017-12-27 16:04:19 WARNING (MainThread) [pyatv.tag_definitions] Unknown data: b’103’
2017-12-27 16:04:19 WARNING (MainThread) [homeassistant.components.media_player.apple_tv] A <class ‘pyatv.exceptions.AuthenticationError’> error occurred: failed to login: 503

If I restart HA, the media_player component (for the atv) is in a state of ‘off’, if I turn it ‘on’, I see:

2017-12-27 16:11:40 WARNING (MainThread) [pyatv.tag_definitions] Unknown data: b’103’
2017-12-27 16:11:40 WARNING (MainThread) [pyatv.tag_definitions] Unknown data: b’103’
2017-12-27 16:11:40 WARNING (MainThread) [homeassistant.components.media_player.apple_tv] A <class ‘pyatv.exceptions.AuthenticationError’> error occurred: failed to login: 503

These messages repeat ever 10secs, while the component is ‘on’.

Should I try to re-authenicate the AppleTV? Not sure what, or how it happened yet…

It never stops apparently :slight_smile: But this looks more like an errounos request or something. Could you maybe enable some additional logging so we can see what is going on? This should be enough:

logger:
  default: info
  logs:
    pyatv.net: debug
    pyatv.daap: debug

For giggles I ran atvremote scan and found that home-sharing was off! Even though settings/accounts/home sharing/ is on, on the atv.

Restarted the atv, atvremote scan now reports a login-id (home-sharing is on), and the component immediately connects…

If in doubt, reboot! yay IT!

I had great troubles with finding one of my ATVs. Even after finally getting it going properly it drops off every so often with login errors etc.

The trick for me is to:

  • turn off home sharing
  • restart ATV
  • re-activate home sharing

Works like a charm but I don’t know if airplay credentials: in my config are affected as I don’t yet (or know how to :stuck_out_tongue: ) take advantage of those yet

Thanks, that help!

I noticed something, and was wondering if someone else could test a theory for me?

Yesterday my component was able to connect, and worked just fine. Today, I get the typical “Establishing a connection to…” message. HA was not restarted between these two times. The only thing that changed was, the Apple TV was put to sleep in the evening, and woken up the following day.
So perhaps home-sharing (which the component requires) is disabled, and/or not re-enabled if the Apple TV is put to sleep?

Just a guess. If we can’t permanently fix the issue, hopefully we can at least narrow it down.

1 Like

Yep, noticed the same, HA is unable to connect after ATV sleeps. :frowning: