home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.81k stars 30.9k forks source link

apple_tv cant authenticate AirPlay #44394

Closed jesperldk closed 3 years ago

jesperldk commented 3 years ago

The problem

With 2020.12 my appletv 4K got autodiscovered, and I try to set it up. It first ask for MRP pin, and it accepts it when I enter it. It then ask for AirPlay pin, and I enter the one my tv shows. However, it does not accept the pin. I have retried several times. Log entered below.

Environment

Problem-relevant configuration.yaml

Traceback/Error logs

2020-12-20 15:55:55 DEBUG (MainThread) [pyatv.mrp.srp] Keys (Input=4eadecbcfbbdd6ee06c27ad534af2de39927f8e1592049c9d8c20f968b9d7fd9, Output=566d0dca4111fffc78e34311abe347f92492ee1fc2ef1f226e7c1e42058091ed)
2020-12-20 15:55:55 DEBUG (MainThread) [pyatv.mrp.connection] 192.168.86.35:40954<->192.168.86.250:49153 Closing connection
2020-12-20 15:55:55 DEBUG (MainThread) [pyatv.airplay.srp] Authentication keys (Private=9ebe02e6c929d8883070a63b73697d94cb31e1cac40954061725532780570159, Public=c3533614017d40a6ff28a137bc7e1653ffa322cb91df31eac6e77ad759603ad5)
2020-12-20 15:55:55 DEBUG (MainThread) [pyatv.airplay.pairing] Starting AirPlay pairing with credentials CC5A500684DE3850:9EBE02E6C929D8883070A63B73697D94CB31E1CAC40954061725532780570159
2020-12-20 15:55:55 DEBUG (MainThread) [pyatv.support.net] POST URL: http://192.168.86.250:7000/pair-pin-start
2020-12-20 15:55:55 DEBUG (MainThread) [pyatv.support.net] >> POST (Data=)
2020-12-20 15:55:55 DEBUG (MainThread) [pyatv.mrp.connection] 192.168.86.35:40954<->192.168.86.250:49153 Disconnected from device: None
2020-12-20 15:55:55 DEBUG (MainThread) [pyatv.support.net] Response: status=200, headers=[Date=Sun, 20 Dec 2020 14:55:55 GMT, Content-Length=0, Server=AirTunes/530.6]
2020-12-20 15:56:02 ERROR (MainThread) [glances_api] Can not load data from Glances API
2020-12-20 15:56:02 ERROR (MainThread) [homeassistant.components.glances] Unable to fetch data from Glances
2020-12-20 15:56:02 ERROR (MainThread) [glances_api] Can not load data from Glances API
2020-12-20 15:56:02 ERROR (MainThread) [homeassistant.components.glances] Unable to fetch data from Glances
2020-12-20 15:56:32 DEBUG (MainThread) [pyatv.airplay.pairing] AirPlay PIN changed to 3279
2020-12-20 15:56:32 DEBUG (MainThread) [pyatv.support.net] POST URL: http://192.168.86.250:7000/pair-setup-pin
2020-12-20 15:56:32 DEBUG (MainThread) [pyatv.support.net] >> POST (Data=62706c6973743030d201020304566d6574686f6454757365725370696e5f101043433541353030363834444533383530080d14191d0000000000000101000000000000000500000000000000000000000000000030)
2020-12-20 15:56:32 DEBUG (MainThread) [pyatv.support.net] Response: status=200, headers=[Date=Sun, 20 Dec 2020 14:56:32 GMT, Content-Length=342, Content-Type=application/x-apple-binary-plist, Server=AirTunes/530.6]
2020-12-20 15:56:32 DEBUG (MainThread) [pyatv.airplay.srp] Client session key: b'623ebe54f333769a02841155a6db6abce0a2bef9c3e2e5d364810a68109ac37b7368b0226190ec41'
2020-12-20 15:56:32 DEBUG (MainThread) [pyatv.airplay.srp] Client public: 9a84706f4f48671fa1837428da5449d75f30de8056aeba32d415ea6be94214e943367ecc35ef5816710404617ac39c3a8828cc2233042996fac298f23a2409361db31edc51ce5b6a73a8552727ee7ccf2ee1d2e4764f75ebabbfebbafa69715184c56cc7aaaea5052c1192b726e5633f3d9bc4d08c16cf2f8217de189e56f5629add5449b3c3e4ef5862322b7cab82d2166684ba55d67a76b40c4a0549f0f15389387f42b0b4770df1805e598b345ad352a25206d777f78e6e8ad1f4b4fe8ba35f8a009d99276bdee43353c605f9e347288a4c3971ac5f8a13f18866fc975d89c35ee747412d71511fea4de388d7a90951f7d9521bd3b4ead4c003b426174d0f, proof: b'8cb5de69a16dd3dec31110edb5fc12821dc8de88'
2020-12-20 15:56:32 DEBUG (MainThread) [pyatv.support.net] POST URL: http://192.168.86.250:7000/pair-setup-pin
2020-12-20 15:56:32 DEBUG (MainThread) [pyatv.support.net] >> POST (Data=62706c6973743030d20102030452706b5570726f6f664f1101009a84706f4f48671fa1837428da5449d75f30de8056aeba32d415ea6be94214e943367ecc35ef5816710404617ac39c3a8828cc2233042996fac298f23a2409361db31edc51ce5b6a73a8552727ee7ccf2ee1d2e4764f75ebabbfebbafa69715184c56cc7aaaea5052c1192b726e5633f3d9bc4d08c16cf2f8217de189e56f5629add5449b3c3e4ef5862322b7cab82d2166684ba55d67a76b40c4a0549f0f15389387f42b0b4770df1805e598b345ad352a25206d777f78e6e8ad1f4b4fe8ba35f8a009d99276bdee43353c605f9e347288a4c3971ac5f8a13f18866fc975d89c35ee7474...)
2020-12-20 15:56:32 DEBUG (MainThread) [pyatv.support.net] Response: status=500, headers=[Content-Length=0, Server=AirTunes/530.6]
2020-12-20 15:56:32 ERROR (MainThread) [homeassistant.components.apple_tv.config_flow] Authentication problem
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/pyatv/support/__init__.py", line 31, in error_handler
    return await func(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/pyatv/airplay/auth.py", line 48, in finish_authentication
    await self._send_plist(
  File "/usr/local/lib/python3.8/site-packages/pyatv/airplay/auth.py", line 69, in _send_plist
    raise AuthenticationError("{0} failed with code {1}".format(step, code))
pyatv.exceptions.AuthenticationError: step2 failed with code 500
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/apple_tv/config_flow.py", line 280, in async_step_pair_with_pin
    await self.pairing.finish()
  File "/usr/local/lib/python3.8/site-packages/pyatv/airplay/pairing.py", line 68, in finish
    await error_handler(
  File "/usr/local/lib/python3.8/site-packages/pyatv/support/__init__.py", line 39, in error_handler
    raise fallback(str(ex)) from ex
pyatv.exceptions.PairingError: step2 failed with code 500

Additional information

probot-home-assistant[bot] commented 3 years ago

apple_tv documentation apple_tv source (message by IssueLinks)

dgomes commented 3 years ago

cc @postlund (please update CODEOWNERS file)

postlund commented 3 years ago

@dgomes I'm already in CODEOWNERS as stated by the manifest. So it's strange I'm not tagged.

postlund commented 3 years ago

@jesperldk Did you change access control to allow all users on the local network?

jesperldk commented 3 years ago

Yes, I did.

Sendt fra min iPhone

Den 23. dec. 2020 kl. 23.17 skrev Pierre Ståhl notifications@github.com:

 @jesperldk Did you change access control to allow all users on the local network?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

postlund commented 3 years ago

@jesperldk Can you download the file http://192.168.86.250:7000/server-info and send it by email to me?

jesperldk commented 3 years ago

http://192.168.86.250:7000/ gives a 403 Access to 192.168.86.250 was denied

Today I tried setting up one of my older Apple TV boxes, and that worked right away. It is my newer 4G box that does not work.

postlund commented 3 years ago

Ok, it seems that requires authentication l. You you try just /info instead?

jesperldk commented 3 years ago

here you go...

On Sat, 26 Dec 2020 at 13:40, Pierre Ståhl notifications@github.com wrote:

Ok, it seems that requires authentication l. You you try just /info instead?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/home-assistant/core/issues/44394#issuecomment-751352269, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGIILC4FKG4VBCTS4SBFC5DSWXKVFANCNFSM4VDEWHAA .

donkawechico commented 3 years ago

I've been using the beta custom component for awhile now with no issues.

I just tried removing the beta and using the core integration instead and I'm getting similar errors (see gif). I've downloaded my /info data and can send via email if you like.

UPDATE Fixed the issue by restarting the Apple TV. I'll keep an eye out for any other issues

postlund commented 3 years ago

@jesperldk Is this still an issue for you (if you test with latest Home Assistant release)? If it is, please send me a new copy of the status file as before, seems like I can't find it.

taw123 commented 3 years ago

Yes I would say it is still an issue. Same situation here. AppleTV 4 adds fine (tvOS 14.4), AppleTV 4K (i.e. gen 5) fails as previously mentioned on the second auth PIN prompt (Airplay auth). If you look at the Apple TV under devices and remotes there WERE a large number ~ 5 remotes (pyatv). I am assuming one for each time I tried to add the ATV to HomeAsst.

I can/will attempt to re-add following up with files and logs assuming folks are still working the issue. I tried all the obvious thing (rebooting server & ATV), clearing out the bogus/failed pairings from the ATV...

Thanks for any help/insights...

--Tom

Basic Env data:

System Health

version core-2021.4.6
installation_type Home Assistant Container
dev false
hassio false
docker true
virtualenv false
python_version 3.8.7
os_name Linux
os_version 4.14.24-qnap
arch x86_64
timezone America/Los_Angeles
Home Assistant Community Store GitHub API | ok -- | -- Github API Calls Remaining | 5000 Installed Version | 1.12.3 Stage | running Available Repositories | 776 Installed Repositories | 20
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Lovelace dashboards | 2 -- | -- resources | 0 views | 2 mode | storage
postlund commented 3 years ago

@taw123 Logs are definitely relevant. It's probably easier if you could try with atvremote directly, as described here: https://pyatv.dev/documentation/atvremote/#pairing-with-a-device

taw123 commented 3 years ago

Thanks for the quick reply.

As you can see 2 ATVs. Per suggestion tried to pair with ATVremote to ATV 4k that fails. Results below. Still failing on AirPlay pairing but a bit more data now here (much easier then harvesting from HA log).

Let me know if you need anything else.

Scan Results
========================================
       Name: Bedroom
   Model/SW: 4K tvOS 13.4.5
    Address: 192.168.42.30
        MAC: D0:D2:B0:A1:3A:4C
 Deep Sleep: False
Identifiers:
 - 2CA1233B-D18E-44C6-A8F7-3538CC4270B4
 - D0:D2:B0:A1:3A:4C
Services:
 - Protocol: MRP, Port: 49271, Credentials: None
 - Protocol: AirPlay, Port: 7000, Credentials: None

       Name: Living Room
   Model/SW: 4 tvOS 14.4
    Address: 192.168.42.27
        MAC: 04:4B:ED:99:75:94
 Deep Sleep: False
Identifiers:
 - 729F2E8D-AFFE-4753-8DCF-0D8AC4EAEAEC
 - 04:4B:ED:99:75:94
Services:
 - Protocol: MRP, Port: 49207, Credentials: None
 - Protocol: AirPlay, Port: 7000, Credentials: None

bash-5.0# atvremote --id D0:D2:B0:A1:3A:4C --protocol mrp pair
Enter PIN on screen: 8154
Pairing seems to have succeeded, yey!
You may now use these credentials: 6209e78d5d93b56bc046d5679761c4c2292e6af8adcbc4e637c2867ac343bae8:6c5c67b8a66c76611a02a258e902ade697691f1945c2b6fa11bfd4adac6f80f7:30353738633763662d336336382d343730392d626136362d656162363032626639633861:38663264613563612d623166322d346462642d613439332d653036306666313161313038
bash-5.0# atvremote --id D0:D2:B0:A1:3A:4C --protocol airplay pair
Enter PIN on screen: 0167
2021-04-30 16:29:18 ERROR: Pairing failed
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/pyatv/support/__init__.py", line 31, in error_handler
    return await func(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/pyatv/airplay/auth.py", line 48, in finish_authentication
    await self._send_plist(
  File "/usr/local/lib/python3.8/site-packages/pyatv/airplay/auth.py", line 69, in _send_plist
    raise AuthenticationError("{0} failed with code {1}".format(step, code))
pyatv.exceptions.AuthenticationError: step2 failed with code 500

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

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/pyatv/scripts/atvremote.py", line 154, in pair
    await self._perform_pairing(pairing)
  File "/usr/local/lib/python3.8/site-packages/pyatv/scripts/atvremote.py", line 188, in _perform_pairing
    await pairing.finish()
  File "/usr/local/lib/python3.8/site-packages/pyatv/airplay/pairing.py", line 68, in finish
    await error_handler(
  File "/usr/local/lib/python3.8/site-packages/pyatv/support/__init__.py", line 39, in error_handler
    raise fallback(str(ex)) from ex
pyatv.exceptions.PairingError: step2 failed with code 500
bash-5.0#
taw123 commented 3 years ago

@postlund Any thoughts or need any further data? Thanks for any help.

gulli1986 commented 3 years ago

@postlund having the exact same problem as described above. First pin works OK, second pin (AirPlay pairing) displays on TV but is not approved when typing it in Home Assistant during set up. Any ideas what it might be?

kelvinlimtg commented 3 years ago

Yes, I am also having the same issue as above. I am using the new Apple TV 4K, previous unit on the 1080p works fine. Let me know if we need more logs. Thanks.

Logger: homeassistant.components.apple_tv.config_flow Source: components/apple_tv/config_flow.py:274 Integration: Apple TV (documentation, issues) First occurred: 5:02:33 PM (13 occurrences) Last logged: 5:03:14 PM

Authentication problem Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/pyatv/support/init.py", line 31, in error_handler return await func(*args, **kwargs) File "/usr/local/lib/python3.8/site-packages/pyatv/airplay/auth.py", line 48, in finish_authentication await self._send_plist( File "/usr/local/lib/python3.8/site-packages/pyatv/airplay/auth.py", line 69, in _send_plist raise AuthenticationError("{0} failed with code {1}".format(step, code)) pyatv.exceptions.AuthenticationError: step2 failed with code 500

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

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/apple_tv/config_flow.py", line 274, in async_step_pair_with_pin await self.pairing.finish() File "/usr/local/lib/python3.8/site-packages/pyatv/airplay/pairing.py", line 68, in finish await error_handler( File "/usr/local/lib/python3.8/site-packages/pyatv/support/init.py", line 39, in error_handler raise fallback(str(ex)) from ex pyatv.exceptions.PairingError: step2 failed with code 500

github-actions[bot] commented 3 years ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.