postlund / pyatv

A client library for Apple TV and AirPlay devices
https://pyatv.dev
MIT License
841 stars 91 forks source link

I'm facing the issue while connecting to the Apple TV using companion protocol. #2125

Closed bhpri closed 10 months ago

bhpri commented 11 months ago

What do you need help with?

I need help in resolve the issue while connecting to Apple TV. Whole errors are below.

imac@192 ~ % atvremote --id 279116E8-5FA1-4C0B-97B0-7D3E64ABC4FE --companion-credentials 8166b931e964d545f38f4a4d54b044b17909fe80fb4ad76ed96fd191949e1b90:6dd69827f95d59385b6e43c13756b31223c4abc8f2b734d7d2c98e86338489ea:32373931313645382d354641312d344330422d393742302d374433453634414243344645:35353462383765382d333261302d343135312d396564302d303439633065663636326139 --debug features
2023-08-05 15:21:03 DEBUG [pyatv.scripts]: Running with pyatv 0.13.3
2023-08-05 15:21:03 DEBUG [pyatv.support.net]: Binding on *:5353
2023-08-05 15:21:03 DEBUG [pyatv.support.net]: Binding on 127.0.0.1:0
2023-08-05 15:21:03 DEBUG [pyatv.support.net]: Binding on 192.168.1.9:0
2023-08-05 15:21:04 DEBUG [pyatv.core.scan]: Auto-discovered iMac’s iMac at 192.168.1.9:49649 via Protocol.Companion ({'rpmac': '1', 'rphn': '6c0b443d4bb6', 'rpfl': '0x36782', 'rpmd': 'AppleTV11,1', 'rpvr': '300.66', 'rpmrtid': '279116E8-5FA1-4C0B-97B0-7D3E64ABC4FE', 'rpad': 'eaf4442e2e85', 'rpba': 'A6:91:25:8F:9A:77'})
2023-08-05 15:21:04 INFO [pyatv.scripts.atvremote]: Auto-discovered iMac’s iMac at 192.168.1.9
2023-08-05 15:21:04 DEBUG [pyatv.core.facade]: Adding handler for protocol Protocol.Companion
2023-08-05 15:21:04 DEBUG [pyatv.core.facade]: Connecting to protocol: Protocol.Companion
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.api]: Connect to Companion from API
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.connection]: Connected to companion device 192.168.1.9:49649
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.protocol]: Companion credentials: 8166b931e964d545f38f4a4d54b044b17909fe80fb4ad76ed96fd191949e1b90:6dd69827f95d59385b6e43c13756b31223c4abc8f2b734d7d2c98e86338489ea:32373931313645382d354641312d344330422d393742302d374433453634414243344645:35353462383765382d333261302d343135312d396564302d303439633065663636326139
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.protocol]: Exchange OPACK: {'_pd': b'\x06\x01\x01\x03 x6\xe7=~\xe6p\xbbM\xa8\xc5\x01\xaao\\\xcc\xed=tF\x1f\xc5\xf5\xd2\xe46KB\x87\xb3\xa5c', '_auTy': 4}
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.protocol]: Send OPACK: {'_pd': b'\x06\x01\x01\x03 x6\xe7=~\xe6p\xbbM\xa8\xc5\x01\xaao\\\xcc\xed=tF\x1f\xc5\xf5\xd2\xe46KB\x87\xb3\xa5c', '_auTy': 4, '_x': 47848}
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.connection]: >> Send data (Data=e3435f7064912506010103207836e73d7ee670bb4da8c501aa6f5ccced3d74461fc5f5d2e4364b4287b3a563455f617554790c425f7831e8ba, FrameType=05)
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.connection]: Received data (Data=060000a6e1435f7064919f0578b9fd8ccda00a915a0ad4af4c325619db07a6b37f187853ff3c879213c4ebfe6982043861af376679458d4f460be325c12e2089fb24d9ec0cfa79028f7df1d48f3046ea0588cdeb3b4f5923a7e4761bed414579f5d533a15b21151fc7a5553733eead8e8163b6ac7269e4b19ab06a58ea7351d4d39f292b6c0601020320e069664c10b088c08dffd06e1da5b30970c032bfbee42479cea1ca48b433f13e)
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.protocol]: Received frame FrameType.PV_Next: b'\xe1C_pd\x91\x9f\x05x\xb9\xfd\x8c\xcd\xa0\n\x91Z\n\xd4\xafL2V\x19\xdb\x07\xa6\xb3\x7f\x18xS\xff<\x87\x92\x13\xc4\xeb\xfei\x82\x048a\xaf7fyE\x8dOF\x0b\xe3%\xc1. \x89\xfb$\xd9\xec\x0c\xfay\x02\x8f}\xf1\xd4\x8f0F\xea\x05\x88\xcd\xeb;OY#\xa7\xe4v\x1b\xedAEy\xf5\xd53\xa1[!\x15\x1f\xc7\xa5U73\xee\xad\x8e\x81c\xb6\xacri\xe4\xb1\x9a\xb0jX\xeasQ\xd4\xd3\x9f)+l\x06\x01\x02\x03 \xe0ifL\x10\xb0\x88\xc0\x8d\xff\xd0n\x1d\xa5\xb3\tp\xc02\xbf\xbe\xe4$y\xce\xa1\xcaH\xb43\xf1>'
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.protocol]: Process incoming auth frame (FrameType.PV_Next): {'_pd': b'\x05x\xb9\xfd\x8c\xcd\xa0\n\x91Z\n\xd4\xafL2V\x19\xdb\x07\xa6\xb3\x7f\x18xS\xff<\x87\x92\x13\xc4\xeb\xfei\x82\x048a\xaf7fyE\x8dOF\x0b\xe3%\xc1. \x89\xfb$\xd9\xec\x0c\xfay\x02\x8f}\xf1\xd4\x8f0F\xea\x05\x88\xcd\xeb;OY#\xa7\xe4v\x1b\xedAEy\xf5\xd53\xa1[!\x15\x1f\xc7\xa5U73\xee\xad\x8e\x81c\xb6\xacri\xe4\xb1\x9a\xb0jX\xeasQ\xd4\xd3\x9f)+l\x06\x01\x02\x03 \xe0ifL\x10\xb0\x88\xc0\x8d\xff\xd0n\x1d\xa5\xb3\tp\xc02\xbf\xbe\xe4$y\xce\xa1\xcaH\xb43\xf1>'}
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.auth]: Device (Encrypted=b9fd8ccda00a915a0ad4af4c325619db07a6b37f187853ff3c879213c4ebfe6982043861af376679458d4f460be325c12e2089fb24d9ec0cfa79028f7df1d48f3046ea0588cdeb3b4f5923a7e4761bed414579f5d533a15b21151fc7a5553733eead8e8163b6ac7269e4b19ab06a58ea7351d4d39f292b6c, Public=8166b931e964d545f38f4a4d54b044b17909fe80fb4ad76ed96fd191949e1b90)
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.protocol]: Exchange OPACK: {'_pd': b'\x06\x01\x03\x05x\xb4y\xf4\x15`\xc2\xf1\xac\xf4qa\xdd+C^o>`q\x18\x99\x15\x8bvV\x95\xbbX\x13\xe6\x90\xf0\x03\xe2\x81\'\xd9\x7fG\xc7\x8ch\x9c\x003\x9a\x95\x9d\xa9\x82o\xc5x\x87\x1a\xc3\x18\xae\x1f\\\x1c.J\x1e\xf0\xec^U\x80S.\xa0v\x92q\xf6j"lKa\xc0\x08\xc7\x93\xf1\xa6\x8c\'Z4!\xe0\xa3\x12\x15\x82\x0f O\x0cV\xcaz\xbe\x020\xb97\x03\xa8\xf5\x1a\x0e3\x9fXb\x8a\xaa'}
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.protocol]: Send OPACK: {'_pd': b'\x06\x01\x03\x05x\xb4y\xf4\x15`\xc2\xf1\xac\xf4qa\xdd+C^o>`q\x18\x99\x15\x8bvV\x95\xbbX\x13\xe6\x90\xf0\x03\xe2\x81\'\xd9\x7fG\xc7\x8ch\x9c\x003\x9a\x95\x9d\xa9\x82o\xc5x\x87\x1a\xc3\x18\xae\x1f\\\x1c.J\x1e\xf0\xec^U\x80S.\xa0v\x92q\xf6j"lKa\xc0\x08\xc7\x93\xf1\xa6\x8c\'Z4!\xe0\xa3\x12\x15\x82\x0f O\x0cV\xcaz\xbe\x020\xb97\x03\xa8\xf5\x1a\x0e3\x9fXb\x8a\xaa', '_x': 47849}
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.connection]: >> Send data (Data=e2435f7064917d0601030578b479f41560c2f1acf47161dd2b435e6f3e60711899158b765695bb5813e690f003e28127d97f47c78c689c00339a959da9826fc578871ac318ae1f5c1c2e4a1ef0ec5e5580532ea0769271f66a226c4b61c008c793f1a68c275a3421e0a31215820f204f0c56ca7abe0230b93703a8f51a0e339f58628aaa425f7831e9ba, FrameType=06)
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.connection]: Received data (Data=06000009e1435f706473060104)
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.protocol]: Received frame FrameType.PV_Next: b'\xe1C_pds\x06\x01\x04'
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.protocol]: Process incoming auth frame (FrameType.PV_Next): {'_pd': b'\x06\x01\x04'}
2023-08-05 15:21:04 DEBUG [pyatv.auth.hap_srp]: Keys (Input=323c4eae6687086472ccb9cbaeaa1e9d6d73f4a3e9bbd744edb6d7ae2492fc90, Output=41c13dffc5502728454fd16d022ba0cc138b2d21361bdee6f56ec0a19668db5e)
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.api]: Sending system information
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.protocol]: Exchange OPACK: {'_i': '_systemInfo', '_t': 2, '_c': {'_bf': 0, '_cf': 512, '_clFl': 128, '_i': 'cafecafecafe', '_idsID': b'554b87e8-32a0-4151-9ed0-049c0ef662a9', '_pubID': 'aa:bb:cc:dd:ee:ff', '_sf': 256, '_sv': '170.18', 'model': 'iPhone14,3', 'name': 'pyatv'}, '_x': 47850}
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.protocol]: Send OPACK: {'_i': '_systemInfo', '_t': 2, '_c': {'_bf': 0, '_cf': 512, '_clFl': 128, '_i': 'cafecafecafe', '_idsID': b'554b87e8-32a0-4151-9ed0-049c0ef662a9', '_pubID': 'aa:bb:cc:dd:ee:ff', '_sf': 256, '_sv': '170.18', 'model': 'iPhone14,3', 'name': 'pyatv'}, '_x': 47850}
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.connection]: >> Send data (Data=e4425f694b5f73797374656d496e666f425f740a425f63ea435f626608435f6366310002455f636c466c3080a04c636166656361666563616665465f6964734944912435353462383765382d333261302d343135312d396564302d303439633065663636326139465f70756249445161613a62623a63633a64643a65653a6666435f7366310001435f7376463137302e3138456d6f64656c4a6950686f6e6531342c33446e616d65457079617476425f7831eaba, FrameType=08)
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.connection]: >> Send (Encrypted=9a482dc037b20beadcede86e06c7ffb2e4e01b749000c0be7a9ae5e313ba30314b922391c207c9c9a33d82c0fb482ab45a69772fce375c0042bcc406bb0c8eba3c91bc0c0b3f5568ddafae2ce8c802c90dce530876769f0bda46099bfb7fdfb21e389d33dbfae5334379fe9be9896fafa7f001168d0f262fa3f17c1b04aabe14bde84784223a8dc36782b0abf8bf39a32240a3565a3c13865152b655c2b3c1010bc04492cfa12ff59a18eb52af4885c24a58166cf919f9bfe4aa178f7412956834c6ff74, Header=080000c4)
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.connection]: Received data (Data=0800017eea4b78b5a557786b2d45fd85e2ae2ed2206c517795c9aa6cbd6b86d82c8e4e19ef7f807d28e7f1ff0e18c7c48195cc7a7a4a20a169015f322c34cacdcff4bb1f0e07a336d424ad4d8ebb9a6e49dc5a016689283dd69a3a53fc34436a2f6f9e9f1207cd4b8f49096e33e0479f8c22738757df84217089441e057a23e4476a46eb6a8c1d69ab6e9fd6bbaa1dc9416e3dc60fdd28c793ed0bce5ca3c08aff40b7a291bdaf77ac65a1ebd543c9853cc3bc67d67e1059bb046a152066edf7a756c6153ca4c64b7e63a2d2bcad413f8666b689aeea259214c778b517b8e0f0c2cd4ab346d2f1ca49bfa5b8b2dec89c5571004ab93d12a6ee5de2e9524ac...)
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.protocol]: Received frame FrameType.E_OPACK: b"\xe3B_c\xedF_pubIDQA6:91:25:8F:9A:77F_mRtIDa$279116E8-5FA1-4C0B-97B0-7D3E64ABC4FEC_svF300.66C_bf1\x80\x07E_mrID\xa4D_stA\xd6Xcom.apple.SeymourSessionScom.apple.LiveAudio\\com.apple.biomesyncd.rapportQcom.apple.SeymourUcom.apple.siri.wakeupRcom.apple.announceB_iL0c16ac50d9b6E_clFl1\x80\x00C_dCGunknownC_cf1\x00\x02C_sf2\x00\x00\x01\x00EmodelKAppleTV11,1Dnamea'Apple TV 4K (at 1080p) (2nd generation)B_t\x0bB_x1\xea\xba"
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.protocol]: Process incoming OPACK frame (FrameType.E_OPACK): {'_c': {'_pubID': 'A6:91:25:8F:9A:77', '_mRtID': '279116E8-5FA1-4C0B-97B0-7D3E64ABC4FE', '_sv': '300.66', '_bf': 1920, '_mrID': '279116E8-5FA1-4C0B-97B0-7D3E64ABC4FE', '_stA': ['com.apple.SeymourSession', 'com.apple.LiveAudio', 'com.apple.biomesyncd.rapport', 'com.apple.Seymour', 'com.apple.siri.wakeup', 'com.apple.announce'], '_i': '0c16ac50d9b6', '_clFl': 128, '_dC': 'unknown', '_cf': 512, '_sf': 65536, 'model': 'AppleTV11,1', 'name': 'Apple TV 4K (at 1080p) (2nd generation)'}, '_t': 3, '_x': 47850}
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.protocol]: Exchange OPACK: {'_i': '_sessionStart', '_t': 2, '_c': {'_srvT': 'com.apple.tvremoteservices', '_sid': 736461563}, '_x': 47851}
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.protocol]: Send OPACK: {'_i': '_sessionStart', '_t': 2, '_c': {'_srvT': 'com.apple.tvremoteservices', '_sid': 736461563}, '_x': 47851}
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.connection]: >> Send data (Data=e4425f694d5f73657373696f6e5374617274425f740a425f63e2455f737276545a636f6d2e6170706c652e747672656d6f74657365727669636573445f73696432fb82e52b425f7831ebba, FrameType=08)
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.connection]: >> Send (Encrypted=4de74646579710de9637d79ef30bd68cfd789e950168a7c8ffb714e4ecb2eff3d9d485368ef20b0925e46b689b034e91c36651ef64feeb354c087a2a4031f8b5420d22d9a7cff3a3ca45377ee17e5ac1044a894992ffa300fa7a43, Header=0800005b)
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.connection]: Received data (Data=080000577bbec9cec94f3300164f9210708f97f115827eccde6beff86d39462980bb61b7dffdc1d73050cbef8711383a696d1bd122a1c6ed4c03a5f36641f756839dcbdb14b85459981caacf8fd94815b7096c6f84c45e0052e673)
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.protocol]: Received frame FrameType.E_OPACK: b'\xe6B_x1\xeb\xbaC_emXUnsupported service typeC_ec2\x03\xea\xfe\xffC_edMRPErrorDomainB_c\xe0B_t\x0b'
2023-08-05 15:21:04 DEBUG [pyatv.protocols.companion.protocol]: Process incoming OPACK frame (FrameType.E_OPACK): {'_x': 47851, '_em': 'Unsupported service type', '_ec': 4294896131, '_ed': 'RPErrorDomain', '_c': {}, '_t': 3}
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pyatv/scripts/atvremote.py", line 762, in _run_application
    return await cli_handler(loop)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pyatv/scripts/atvremote.py", line 535, in cli_handler
    return await _handle_commands(args, config, loop)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pyatv/scripts/atvremote.py", line 639, in _handle_commands
    atv = await connect(config, loop, protocol=args.protocol)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pyatv/__init__.py", line 135, in connect
    await atv.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pyatv/core/facade.py", line 681, in connect
    if await setup_data.connect():
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pyatv/protocols/companion/__init__.py", line 573, in _connect
    await api.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pyatv/protocols/companion/api.py", line 146, in connect
    await self._session_start()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pyatv/protocols/companion/api.py", line 201, in _session_start
    resp = await self._send_command(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pyatv/protocols/companion/api.py", line 163, in _send_command
    resp = await self._protocol.exchange_opack(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pyatv/protocols/companion/protocol.py", line 157, in exchange_opack
    return await self._exchange_generic_opack(frame_type, data, identifier, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pyatv/protocols/companion/protocol.py", line 178, in _exchange_generic_opack
    raise exceptions.ProtocolError(f"Command failed: {unpacked_object['_em']}")
pyatv.exceptions.ProtocolError: Command failed: Unsupported service type

Thanks & Regards...

postlund commented 11 months ago

That should not happen. Can you try rebooting the Apple TV?

bhpri commented 11 months ago

Yes i Rebooted Apple TV but error not resolved

postlund commented 11 months ago

Just a quick question: is your device not signed into a iCloud/apple account?

bhpri commented 11 months ago

Yes, Device is signed into a iCloud account

postlund commented 11 months ago

That's so strange because _systemInfo does not include any information about your account (which it normally does). Can you verify that access setting under AirPlay still is set to "Everyone on the same network"? If it's still the same, try pairing again and verify if the behavior is still the same with the new credentials. One interesting thing to test is launching an app using the shortcut app in iOS works (that's one thing that might break if that service is missing). Just open the shortcuts app and create a new shortcut that opens a participant app on your Apple TV. If you can list install apps, then it works. One last resort is to logout your account and log back in to see if that works.

bhpri commented 11 months ago

Airplay is set to "Everyone on the same network", Paired again, and I try to get a list of installed apps, and from the package name, I also try to launch the app, but the error is not resolved. Same error I get every time.

postlund commented 11 months ago

I just want to confirm that you try to list and launch apps from the shortcuts app in iOS, not pyatv (as that will obviously not work)?

bhpri commented 11 months ago

I haven't tried to launch an app from iOS yet.

postlund commented 11 months ago

Try that, I want to make sure it works with iOS so we aren't chasing ghosts. It happens from time to time that I get trouble reports for things that doesn't even work in iOS (making it impossible for me to fix that in pyatv).