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

Unable to Authenticate to Apple TV #1

Open
boojew opened this issue Aug 21, 2019 · 38 comments
Open

Unable to Authenticate to Apple TV #1

boojew opened this issue Aug 21, 2019 · 38 comments

Comments

@boojew
Copy link

@boojew boojew commented Aug 21, 2019

Thanks for the MRP fix! Unfortunately, I have not been able to get it to work :( I can initiate a scan, and get the IPs and ports, but when I run I restart and run the authentication service (apple_tv_mrp.apple_tv_mrp_authenticate), I get the following error

'2' Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 128, in handle_call_service connection.context(msg), File "/usr/src/homeassistant/homeassistant/core.py", line 1235, in async_call await asyncio.shield(self._execute_service(handler, service_call)) File "/usr/src/homeassistant/homeassistant/core.py", line 1260, in _execute_service await handler.func(service_call) File "/config/custom_components/apple_tv_mrp/__init__.py", line 169, in async_service_handler await atv.pairing.start() File "/config/custom_components/apple_tv_mrp/pyatv_mrp/mrp/__init__.py", line 322, in start await self.pairing_procedure.start_pairing() File "/config/custom_components/apple_tv_mrp/pyatv_mrp/mrp/pairing.py", line 44, in start_pairing self._atv_salt = pairing_data[tlv8.TLV_SALT] KeyError: '2'

I have removed my old apple tv entities and the old config slugs in configuration.yaml and I just have

`apple_tv_mrp:

  • name: Home Theater Apple TV
    host: 192.168.0.62
    port: 49155
  • name: Bedroom Apple TV
    host: 192.168.0.64
    port: 49152
  • name: Living Room Apple TV
    host: 192.168.0.65
    port: 49155 `

I'm running hassio 0.97.2 on supervisor 181. Oh and I installed voa HACS

@chamberlain2007

This comment has been minimized.

Copy link
Owner

@chamberlain2007 chamberlain2007 commented Aug 21, 2019

Hey, thanks for trying this out. Seems a couple people are having this issue. I think it might be on the pyatv side. Could you try checking out the master branch of pyatv on any old computer on your network (https://github.com/postlund/pyatv) then run it like:

python3 -m pyatv --address 10.0.0.6 --port 49153 --protocol mrp pair

Let me know if that works. If it does, then it's something on my end. If not, then you'll need to file something in the pyatv repo's issues.

@boojew

This comment has been minimized.

Copy link
Author

@boojew boojew commented Aug 21, 2019

After installing a ton of dependencies, I get this

Bens-MBP:pyatv ben$ python3 -m pyatv --address 192.168.0.62 --port 49155 --protocol mrp pair
Traceback (most recent call last):
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/runpy.py", line 142, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "/Users/ben/Downloads/pyatv/pyatv/__init__.py", line 19, in <module>
    from pyatv.mrp import MrpAppleTV
  File "/Users/ben/Downloads/pyatv/pyatv/mrp/__init__.py", line 7, in <module>
    from pyatv.mrp.srp import SRPAuthHandler
  File "/Users/ben/Downloads/pyatv/pyatv/mrp/srp.py", line 15, in <module>
    from pyatv.mrp import (tlv8, chacha20)
  File "/Users/ben/Downloads/pyatv/pyatv/mrp/chacha20.py", line 2, in <module>
    from tlslite.utils.chacha20_poly1305 import CHACHA20_POLY1305
  File "/Library/Python/3.7/site-packages/tlslite/__init__.py", line 27, in <module>
    from tlslite.api import *
  File "/Library/Python/3.7/site-packages/tlslite/api.py", line 11, in <module>
    from .tlsconnection import TLSConnection
  File "/Library/Python/3.7/site-packages/tlslite/tlsconnection.py", line 71
    async=False):
        ^
SyntaxError: invalid syntax

@boojew

This comment has been minimized.

Copy link
Author

@boojew boojew commented Aug 21, 2019

Sorry - just properly read the docs. I see that there is a pip package for this. Oops. Ok installed, but I get this now

ben@skywarp:/tmp# python3  -m pyatv --address 192.168.0.62 --port 49153  --protocol mrp pair
usage: __main__.py [-h] [--name NAME] [--address ADDRESS] [-t TIMEOUT]
                   [--version] [--remote-name REMOTE_NAME] [-p PIN]
                   [--pairing-guid PAIRING_GUID] [-a | --login_id LOGIN_ID]
                   [--airplay_credentials AIRPLAY_CREDENTIALS] [-v] [--debug]
                   command [command ...]
__main__.py: error: unrecognized arguments: --port --protocol mrp pair
@chamberlain2007

This comment has been minimized.

Copy link
Owner

@chamberlain2007 chamberlain2007 commented Aug 21, 2019

So you were on the right track - you do need to check out the repo and use the master branch. The version on PyPi doesn’t have the MRP protocol which is why I had to go through so much effort to update it. Your error with the “invalid syntax” is that you need to uninstall the tlslite pip package and install tlslite-ng

@boojew

This comment has been minimized.

Copy link
Author

@boojew boojew commented Aug 22, 2019

Ah. I see the dependencies in the setup file. Slow me. :)

Bens-MBP:pyatv ben$  python3  -m pyatv --address 192.168.0.62 --port 49155  --protocol mrp pair
Traceback (most recent call last):
  File "/Users/ben/Downloads/pyatv/pyatv/__main__.py", line 490, in _run_application
    return await cli_handler(loop)
  File "/Users/ben/Downloads/pyatv/pyatv/__main__.py", line 315, in cli_handler
    return await _handle_commands(args, loop)
  File "/Users/ben/Downloads/pyatv/pyatv/__main__.py", line 405, in _handle_commands
    ret = await _handle_device_command(args, cmd, atv, loop)
  File "/Users/ben/Downloads/pyatv/pyatv/__main__.py", line 426, in _handle_device_command
    DeviceCommands(atv, loop, args), cmd, False, *cmd_args))
  File "/Users/ben/Downloads/pyatv/pyatv/__main__.py", line 456, in _exec_command
    value = await tmp(*args)
  File "/Users/ben/Downloads/pyatv/pyatv/__main__.py", line 166, in pair
    await self.atv.pairing.start()
  File "/Users/ben/Downloads/pyatv/pyatv/mrp/__init__.py", line 322, in start
    await self.pairing_procedure.start_pairing()
  File "/Users/ben/Downloads/pyatv/pyatv/mrp/pairing.py", line 44, in start_pairing
    self._atv_salt = pairing_data[tlv8.TLV_SALT]
KeyError: '2'

>>> An error occurred, full stack trace above

Looks like this is the same thing as postlund/pyatv#180 :(

@chamberlain2007

This comment has been minimized.

Copy link
Owner

@chamberlain2007 chamberlain2007 commented Aug 22, 2019

Ah darn. Ok, well we'll need to follow up with postlund then. Sorry about that. If he's able to get things sorted out, I'm happy to bring whatever he changes back in here and update the hass component.

@boojew

This comment has been minimized.

Copy link
Author

@boojew boojew commented Sep 16, 2019

I'm using hass 0.99 w/ your custom module, and it works now using the latest TvOS 13 beta update

@jimz011

This comment has been minimized.

Copy link

@jimz011 jimz011 commented Sep 16, 2019

I have the same issue it seems :(

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 130, in handle_call_service
    connection.context(msg),
  File "/usr/src/homeassistant/homeassistant/core.py", line 1234, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
  File "/usr/src/homeassistant/homeassistant/core.py", line 1259, in _execute_service
    await handler.func(service_call)
  File "/config/custom_components/apple_tv_mrp/__init__.py", line 169, in async_service_handler
    await atv.pairing.start()
  File "/config/custom_components/apple_tv_mrp/pyatv_mrp/mrp/__init__.py", line 322, in start
    await self.pairing_procedure.start_pairing()
  File "/config/custom_components/apple_tv_mrp/pyatv_mrp/mrp/pairing.py", line 44, in start_pairing
    self._atv_salt = pairing_data[tlv8.TLV_SALT]
KeyError: '2'

It seems it doesnt want to pair. This is tried on a fresh Hass.io install (Ubuntu/docker). It was able to scan for the devices though. I will try to pair them manually if there is a way.

@ahkaroly

This comment has been minimized.

Copy link

@ahkaroly ahkaroly commented Sep 23, 2019

Hi,

Thanks for your work :)

I have the same issue it seems :(

'2' Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 130, in handle_call_service connection.context(msg), File "/usr/src/homeassistant/homeassistant/core.py", line 1234, in async_call await asyncio.shield(self._execute_service(handler, service_call)) File "/usr/src/homeassistant/homeassistant/core.py", line 1259, in _execute_service await handler.func(service_call) File "/config/custom_components/apple_tv_mrp/__init__.py", line 169, in async_service_handler await atv.pairing.start() File "/config/custom_components/apple_tv_mrp/pyatv_mrp/mrp/__init__.py", line 322, in start await self.pairing_procedure.start_pairing() File "/config/custom_components/apple_tv_mrp/pyatv_mrp/mrp/pairing.py", line 44, in start_pairing self._atv_salt = pairing_data[tlv8.TLV_SALT] KeyError: '2'

I'm running hassio 0.99.2, latest TvOS 13 beta

@geekofweek

This comment has been minimized.

Copy link

@geekofweek geekofweek commented Sep 24, 2019

@boojew do you mind sharing how you got it to work, hitting a wall here with trying to authenticate.

@dvd77

This comment has been minimized.

Copy link

@dvd77 dvd77 commented Sep 25, 2019

same here... With TVOS 13 (official release) and HA 0.99.2 I am running into the authentication error 2

@geekofweek

This comment has been minimized.

Copy link

@geekofweek geekofweek commented Sep 25, 2019

I'm willing to throw in some effort behind this and help get it all cleaned up and merged into the main integration if it works.

I'll try and get some network captures and see if I can figure out the payloads that the app is sending to the Apple TV and go from there.

@rjmcfadd

This comment has been minimized.

Copy link

@rjmcfadd rjmcfadd commented Sep 25, 2019

I found out that you don't actually need to authenticate it to be able to use the play/paused status for automations.

@geekofweek

This comment has been minimized.

Copy link

@geekofweek geekofweek commented Sep 25, 2019

@rjmcfadd really... go on. I just get can't connect

@rjmcfadd

This comment has been minimized.

Copy link

@rjmcfadd rjmcfadd commented Sep 25, 2019

Once you add this information to your config

`apple_tv_mrp:

  • name: Bedroom Apple TV
    host: 10.0.0.6
    port: 49154`

It creates an entity that you can now use. For example, the play/paused status can be used to control your lights without it being authenticated.

@geekofweek

This comment has been minimized.

Copy link

@geekofweek geekofweek commented Sep 25, 2019

How about that, that solves a pretty big automation issue I had.

@boojew

This comment has been minimized.

Copy link
Author

@boojew boojew commented Sep 25, 2019

Yea, I can play/pause and see what is playing.... Not sure if I authenticated or not. What I realized last night though is that I had tested this with only my ATV 4K. My two non-4K units do not work. All are on the latest TvOS 13 beta. Probably a coincidence that it doesnt work on the non-4ks

@geekofweek

This comment has been minimized.

Copy link

@geekofweek geekofweek commented Sep 25, 2019

Interesting I just tested on a non 4k Apple TV 4 and it worked, will test the two 4Ks and see how it works.

@geekofweek

This comment has been minimized.

Copy link

@geekofweek geekofweek commented Sep 25, 2019

Works on all of them, I didn't even attempt to test it. Still like to solve the rest and make it more like the old one, but this solves an immediate problem. Guess I should have actually tested first. Appreciate that.

@emergentjlr

This comment has been minimized.

Copy link

@emergentjlr emergentjlr commented Sep 25, 2019

I'm having this issue as well. Authentication is required to be able to send a camera feed to the Apple TV, which is my main use for it.

@LintHart

This comment has been minimized.

Copy link

@LintHart LintHart commented Sep 26, 2019

Also having authentication issues. Original Gen 4 device running the latest full release of TVOS 13. I do have multiple users which isn’t something I’m likely to able to give up but we’ll see I guess.

Also running along side the original integration for another similar evidence that has not yet been updated.

Interesting question, if this uses an extended remote protocol, could it be finally possible to make them sleep?

Thank you very much :)

@chamberlain2007

This comment has been minimized.

Copy link
Owner

@chamberlain2007 chamberlain2007 commented Sep 26, 2019

Hey folks, sorry for the delays. Gotta deal with the day job first and foremost!

So the KeyError 2 bug is in the pyatv module at postlund/pyatv#180. To get it fixed, postlund is requesting a network dump over there. We need to follow up on that issue over there.

@geekofweek Over in postlund/pyatv#181 is where we're tracking that. I definitely want to get that all done, but obviously day job comes first. Getting pyatv #180 resolved is step 1, and then getting anything else outstanding on that issue so that we can get the MRP code pushed to PyPI, then we can get the relevant code from this module properly integrated/merged into the main HA component.

@LintHart

This comment has been minimized.

Copy link

@LintHart LintHart commented Sep 26, 2019

@chamberlain2007 I appreciate the information thank you :)

@emergentjlr

This comment has been minimized.

Copy link

@emergentjlr emergentjlr commented Sep 26, 2019

I definitely understand the day job issue. But you’re doing things that I can’t that are way more useful than you realize. If I can donate to you for your help just let me know.

@ahkaroly

This comment has been minimized.

Copy link

@ahkaroly ahkaroly commented Sep 26, 2019

The hassio has just been updated (0.99.3) and apple tv integration has started to work.

If I go to authenticate I still write error 2 but it started to work.

image

@Bluhme1

This comment has been minimized.

Copy link

@Bluhme1 Bluhme1 commented Sep 26, 2019

Unfortunately not here. Same as before update

@jimz011

This comment has been minimized.

Copy link

@jimz011 jimz011 commented Sep 26, 2019

Authentication does not work indeed, but retrieving playing/paused state and media info does work. Tested on both ATV4 and ATV4K.

You can try this by adding your ATV to your config (as mentioned in the docs) but without the credentials.

You wont be able to use stream/airplay but you can have automations on the play/pause state. Remote also seems to work. Note that it only retrieves a state once your ATV starts playing. Before that it will say credentials needed. So start a video first.

@poudenes

This comment has been minimized.

Copy link

@poudenes poudenes commented Oct 6, 2019

I also get this error. I have the AppleTV 4 no K :D

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 130, in handle_call_service
    connection.context(msg),
  File "/usr/src/homeassistant/homeassistant/core.py", line 1234, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
  File "/usr/src/homeassistant/homeassistant/core.py", line 1259, in _execute_service
    await handler.func(service_call)
  File "/config/custom_components/apple_tv_mrp/__init__.py", line 169, in async_service_handler
    await atv.pairing.start()
  File "/config/custom_components/apple_tv_mrp/pyatv_mrp/mrp/__init__.py", line 322, in start
    await self.pairing_procedure.start_pairing()
  File "/config/custom_components/apple_tv_mrp/pyatv_mrp/mrp/pairing.py", line 44, in start_pairing
    self._atv_salt = pairing_data[tlv8.TLV_SALT]
KeyError: '2'

I don't know if this gives the problem that I cant see the IDLE status?

@postlund

This comment has been minimized.

Copy link

@postlund postlund commented Oct 8, 2019

I fixed the pairing isues a couple of days ago, but they are not backported here. My intentions are to get the integration in Home Assistant up-to-date and support MRP natively (the way it should be). Current state of pyatv should be good enough to modify the integration and have it work similarily to how this component works (same feature set).

My time is still very limited (and I have another child coming pretty much any day now), so any help working on the integration is appreciated.

@postlund

This comment has been minimized.

Copy link

@postlund postlund commented Oct 8, 2019

For reference: postlund/pyatv#209

@0evmc

This comment has been minimized.

Copy link

@0evmc 0evmc commented Oct 22, 2019

Hello. The main thing I am needing at the moment is the ability to detect the state (playing, paused,idle) of the AppleTVs, but I am having the authentication issue. I saw where some said they did not have to authenticate to accomplish this, but that does not appear to be the case for me. I'm running HA 0.100.3 currently.

Update:
Result on ATV when trying to authenticate:

Failed to call service apple_tv_mrp/apple_tv_mrp_authenticate. [Errno 111] Connect call failed ('10.1.1.10', 49154)

• Unable to view the playing status of ATV.

Result on ATV4K when trying to authenticate:

Failed to call service apple_tv_mrp/apple_tv_mrp_authenticate. '2'

• Successfully view the playing status of ATV4K
Update:
After a reboot, ATV4K just says "Establishing a connection to AppleTV..." until something is played on the appleTV

If there is some other custom_component I could use to meet this need, I'd appreciate a URL. Thanks!

@Bluhme1

This comment has been minimized.

Copy link

@Bluhme1 Bluhme1 commented Nov 16, 2019

@chamberlain2007
Perhaps you know already. Postlund made a new pyatv that solves a lot of problems.
https://postlund.github.io/pyatv//getting-started/
Will this be integrated in your component?

@postlund

This comment has been minimized.

Copy link

@postlund postlund commented Nov 16, 2019

@chamberlain2007
Perhaps you know already. Postlund made a new pyatv that solves a lot of problems.
https://postlund.github.io/pyatv//getting-started/
Will this be integrated in your component?

My intention is to re-write the official component (which I'm of course is the author of) using the newer pyatv, rendering this integration obsolete in the long run. As mentioned above, progress is tracked at postlund/pyatv#209. In the long run this means support is restored in Home Assistant out of the box

@Bluhme1

This comment has been minimized.

Copy link

@Bluhme1 Bluhme1 commented Nov 16, 2019

@postlund. Sounds great. I use Hassio and cannot consequently run pip. What do I do if I want to test your recent build?

@postlund

This comment has been minimized.

Copy link

@postlund postlund commented Nov 16, 2019

@postlund. Sounds great. I use Hassio and cannot consequently run pip. What do I do if I want to test your recent build?

Due to some limitations of custom components, it's not possible to develop it as a custom components. So I'm doing it in-tree, which means you must run a separate version of Home Assistant (based on my branch). So it's hard to integrate in an existing instance, you'll more or less have to run a second Home Assistant for testing.

@Bluhme1

This comment has been minimized.

Copy link

@Bluhme1 Bluhme1 commented Nov 16, 2019

Ok. It sound a bit complicated. I’d better wait for an integration in a future version of HA.
Thanks for your great work. Greetings from Denmark - your neighbor

@postlund

This comment has been minimized.

Copy link

@postlund postlund commented Nov 16, 2019

Ok. It sound a bit complicated. I’d better wait for an integration in a future version of HA.
Thanks for your great work. Greetings from Denmark - your neighbor

Yeah, unless you feel like beta testing for real then it's best to wait. I hope to be able to deliver by the end of the year, let's see if I manage! 👍

@bramhendriks

This comment has been minimized.

Copy link

@bramhendriks bramhendriks commented Dec 22, 2019

Hi, also have some issues with the authentication of the Apple TV. Custom module in home assistant seems to be able to find the apple tv while scanning the network. But after adding the configuration to the configuration.yaml file i get the following error:

'data_apple_tv_mrp_entities'
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 133, in handle_call_service
connection.context(msg),
File "/usr/src/homeassistant/homeassistant/core.py", line 1235, in async_call
await asyncio.shield(self._execute_service(handler, service_call))
File "/usr/src/homeassistant/homeassistant/core.py", line 1260, in _execute_service
await handler.func(service_call)
File "/config/custom_components/apple_tv_mrp/init.py", line 161, in async_service_handler
for device in hass.data[DATA_ENTITIES]
KeyError: 'data_apple_tv_mrp_entities'
Kan service apple_tv_mrp/apple_tv_mrp_authenticate niet aanroepen 'data_apple_tv_mrp_entities'

No entry of the Apple TV shows up in the Entity list of home assistant. Any updates if Home assistant added native support yet?

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

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.