postlund / pyatv

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

Unable to test command #1322

Closed martinorob closed 3 years ago

martinorob commented 3 years ago

Describe the bug

Pairing successful. Trying example play command doesn't works.

Thanks for any help

Error log

######PAIR######
python3 /usr/local/bin/atvremote --id C869CD6E4386  --protocol airplay pair                                                          1 ⨯
Enter PIN on screen: 6595
Pairing seems to have succeeded, yey!
You may now use these credentials: 6DDEFC2708CD4724:950D03F238C291BDCA1F09B12F46C9C9DE6107018BD1E1F009E60D0CF993E807

echo "6DDEFC2708CD4724:950D03F238C291BDCA1F09B12F46C9C9DE6107018BD1E1F009E60D0CF993E807" > credentials

#####END_PAIR#####

######PLAY######
python3 /usr/local/bin/atvremote --id C869CD6E4386  --airplay-credentials `cat credentials` play --debug

2021-09-22 13:56:44 DEBUG [pyatv.support.net]: Binding on *:5353
2021-09-22 13:56:44 DEBUG [pyatv.support.net]: Binding on 127.0.0.1:0
2021-09-22 13:56:44 DEBUG [pyatv.support.net]: Binding on 192.168.3.80:0
2021-09-22 13:56:44 DEBUG [pyatv.support.scan]: Auto-discovered AppleTV at 192.168.3.52:7000 via Protocol.AirPlay ({'acl': '0', 'btaddr': 'C8:69:CD:6E:43:85', 'deviceid': 'C8:69:CD:6E:43:86', 'fex': '1d9/Wt5fFbwI', 'features': '0x5A7FDFD5,0xBC155FDE', 'flags': '0x1644', 'gid': 'C87AD4D2-8E40-49A6-8C0F-DF0D3FE982BC', 'igl': '1', 'gcgl': '1', 'model': 'AppleTV5,3', 'protovers': '1.1', 'pi': '91688c86-df11-4c30-a35d-20c8bf8dd54d', 'psi': 'F81B0864-E26B-40BA-BB2C-163ED5F200BE', 'pk': 'f096f8e419ca6a0a76d3fafed380afe4b8f54dc4888980eb25c634ed746d92c5', 'srcvers': '566.25.43', 'osvers': '15.0', 'vv': '2'})
2021-09-22 13:56:44 DEBUG [pyatv.support.scan]: Auto-discovered AppleTV at 192.168.3.52:49153 via Protocol.Companion ({'rpmac': '1', 'rphn': '47b8f2f0cfb8', 'rpfl': '0x36782', 'rpha': '9c53b224af0d', 'rpmd': 'AppleTV5,3', 'rpvr': '300.66', 'rpad': '010b4f16a6c5', 'rphi': '3bcbb0fb32c0', 'rpba': '32:37:65:C9:AC:D0', 'rpmrtid': 'F81B0864-E26B-40BA-BB2C-163ED5F200BE'})
2021-09-22 13:56:44 DEBUG [pyatv.support.scan]: Auto-discovered AppleTV at 192.168.3.52:49152 via Protocol.MRP ({'modelname': 'Apple TV', 'allowpairing': 'YES', 'bluetoothaddress': "b'\\xc8i\\xcdnC\\x85'", 'macaddress': 'c8:69:cd:6e:43:86', 'name': 'AppleTV', 'uniqueidentifier': '8CD254F3-CA9C-4B4C-AEBD-113FC050DD45', 'systembuildversion': '19J346', 'localairplayreceiverpairingidentity': 'F81B0864-E26B-40BA-BB2C-163ED5F200BE'})
2021-09-22 13:56:44 DEBUG [pyatv.support.scan]: Auto-discovered C869CD6E4386@AppleTV at 192.168.3.52:7000 via Protocol.RAOP ({'cn': '0,1,2,3', 'da': 'true', 'et': '0,3,5', 'ft': '0x5A7FDFD5,0xBC155FDE', 'sf': '0x1644', 'md': '0,1,2', 'am': 'AppleTV5,3', 'pk': 'f096f8e419ca6a0a76d3fafed380afe4b8f54dc4888980eb25c634ed746d92c5', 'tp': 'UDP', 'vn': '65537', 'vs': '566.25.43', 'ov': '15.0', 'vv': '2'})
2021-09-22 13:56:44 INFO [root]: Auto-discovered AppleTV at 192.168.3.52
2021-09-22 13:56:44 DEBUG [pyatv.airplay]: Loaded AirPlay credentials: 6DDEFC2708CD4724:950D03F238C291BDCA1F09B12F46C9C9DE6107018BD1E1F009E60D0CF993E807
2021-09-22 13:56:44 DEBUG [pyatv]: Adding protocol Protocol.AirPlay
2021-09-22 13:56:44 DEBUG [pyatv]: Not adding protocol: Protocol.Companion
2021-09-22 13:56:44 DEBUG [pyatv]: Adding protocol Protocol.MRP
2021-09-22 13:56:44 DEBUG [pyatv]: Adding protocol Protocol.RAOP
2021-09-22 13:56:44 DEBUG [pyatv.mrp.connection]: Connection made to device
2021-09-22 13:56:44 DEBUG [pyatv.support.net]: Configured keep-alive on <asyncio.TransportSocket fd=6, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('192.168.3.80', 54341), raddr=('192.168.3.52', 49152)> (Darwin)
2021-09-22 13:56:44 DEBUG [pyatv.mrp.connection]: 192.168.3.80:54341<->192.168.3.52:49152  Connection established
2021-09-22 13:56:44 DEBUG [pyatv.mrp.connection]: 192.168.3.80:54341<->192.168.3.52:49152 >> Send (Data=080f122446424434344141382d373646362d344232362d413633372d4138343439363846434242302000a20183010a2465396132326636372d663066612d346537342d393838652d306336326435313564313064120570796174761a066950686f6e6522063138413339332a12636f6d2e6170706c652e545652656d6f746532063334342e32383801406c480150016211636f6d2e6170706c652e54564d75736963680170017801880102a80101b00101)
2021-09-22 13:56:44 DEBUG [pyatv.mrp.connection]: 192.168.3.80:54341<->192.168.3.52:49152 >> Send: Protobuf: type: DEVICE_INFO_MESSAGE
identifier: "FBD44AA8-76F6-4B26-A637-A844968FCBB0"
errorCode: NoError
[deviceInfoMessage] {
  uniqueIdentifier: "e9a22f67-f0fa-4e74-988e-0c62d515d10d"
  name: "pyatv"
  localizedModelName: "iPhone"
  systemBuildVersion: "18A393"
  applicationBundleIdentifier: "com.apple.TVRemote"
  applicationBundleVersion: "344.28"
  protocolVersion: 1
  lastSupportedMessageType: 108
  supportsSystemPairing: true
  allowsPairing: true
  systemMediaApplication: "com.apple.TVMusic"
  supportsACL: true
  supportsSharedQueue: true
  supportsExtendedMotion: true
  sharedQueueVersion: 2
  deviceClass: iPhone
  logicalDeviceCount: 1
}
2021-09-22 13:56:49 DEBUG [pyatv.mrp.connection]: 192.168.3.80:54341<->192.168.3.52:49152  Closing connection
2021-09-22 13:56:49 DEBUG [pyatv.mrp.connection]: 192.168.3.80:54341<->192.168.3.52:49152  Disconnected from device: None
2021-09-22 13:56:49 DEBUG [pyatv.mrp.connection]: 192.168.3.80:54341<->192.168.3.52:49152  Closing connection
Traceback (most recent call last):
  File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/locks.py", line 413, in acquire
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/tasks.py", line 492, in wait_for
    fut.result()
asyncio.exceptions.CancelledError

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

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/pyatv/scripts/atvremote.py", line 724, in _run_application
    return await cli_handler(loop)
  File "/usr/local/lib/python3.9/site-packages/pyatv/scripts/atvremote.py", line 504, in cli_handler
    return await _handle_commands(args, config, loop)
  File "/usr/local/lib/python3.9/site-packages/pyatv/scripts/atvremote.py", line 612, in _handle_commands
    atv = await connect(config, loop, protocol=args.protocol)
  File "/usr/local/lib/python3.9/site-packages/pyatv/__init__.py", line 127, in connect
    await atv.connect()
  File "/usr/local/lib/python3.9/site-packages/pyatv/support/facade.py", line 412, in connect
    await protocol_connect()
  File "/usr/local/lib/python3.9/site-packages/pyatv/mrp/__init__.py", line 743, in _connect
    await protocol.start()
  File "/usr/local/lib/python3.9/site-packages/pyatv/mrp/protocol.py", line 129, in start
    self.device_info = await self.send_and_receive(msg)
  File "/usr/local/lib/python3.9/site-packages/pyatv/mrp/protocol.py", line 216, in send_and_receive
    return await self._receive(identifier, timeout)
  File "/usr/local/lib/python3.9/site-packages/pyatv/mrp/protocol.py", line 224, in _receive
    await asyncio.wait_for(semaphore.acquire(), timeout)
  File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/tasks.py", line 494, in wait_for
    raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError

>>> An error occurred, full stack trace above

How to reproduce the bug?

See above

What is expected behavior?

Play

Operating System

Linux

Python

3.8

pyatv

0.9.0

Device

Apple TV HD 15.0

Additional context

NO additional context

postlund commented 3 years ago

Ok, so this is an interesting side-effect of the final version of tvOS 15 for some reason announcing a non-working MRP service. As pyatv will try to connect to all services found during a scan, this will fail. @Qonstrukt found that resetting the device fixed the problem. I expect more people to experience this though, so I need to come up with some kind of fix for it.

As a work-around until then, you can specify which protocols to scan for and make it work anyway:

python3 /usr/local/bin/atvremote --id C869CD6E4386  --airplay-credentials `cat credentials` --scan-protocols airplay play

If you need other protocols (Companion or RAOP for instance), just add them too (e.g. airplay,companion,raop).

martinorob commented 3 years ago

Well! I think now i’m very close but i have another error..

`

python3 atvremote --id C869CD6E4386 --airplay-credentials "4571016E185B3B5D:19CA3D069FA9A173CDA715746D1E682F5E4D390026A6F22FA4FE40B75FCDDFAC" --scan-protocols airplay play

2021-09-22 14:43:37 ERROR [root]: Could not find any Apple TV on current network

`

DEBUG

`

2021-09-22 14:44:45 DEBUG [pyatv.support.net]: Binding on *:5353 2021-09-22 14:44:45 DEBUG [pyatv.support.net]: Binding on 127.0.0.1:0 2021-09-22 14:44:45 DEBUG [pyatv.support.net]: Binding on 192.168.3.80:0 2021-09-22 14:44:48 DEBUG [pyatv.support.scan]: Auto-discovered AppleTV at 192.168.3.52:7000 via Protocol.AirPlay ({'acl': '0', 'btaddr': 'C8:69:CD:6E:43:85', 'deviceid': 'C8:69:CD:6E:43:86', 'fex': '1d9/Wt5fFbwI', 'features': '0x5A7FDFD5,0xBC155FDE', 'flags': '0x1644', 'gid': 'C87AD4D2-8E40-49A6-8C0F-DF0D3FE982BC', 'igl': '1', 'gcgl': '1', 'model': 'AppleTV5,3', 'protovers': '1.1', 'pi': '91688c86-df11-4c30-a35d-20c8bf8dd54d', 'psi': 'F81B0864-E26B-40BA-BB2C-163ED5F200BE', 'pk': 'f096f8e419ca6a0a76d3fafed380afe4b8f54dc4888980eb25c634ed746d92c5', 'srcvers': '566.25.43', 'osvers': '15.0', 'vv': '2'}) 2021-09-22 14:44:48 DEBUG [pyatv.support.scan]: Auto-discovered TV at 192.168.3.27:7000 via Protocol.AirPlay ({'acl': '0', 'deviceid': '00:F7:6F:D4:4B:0A', 'features': '0x445D0A00,0x1C340', 'rsf': '0x0', 'fv': 'p20.78100.3', 'flags': '0x804', 'model': 'AirPort10,115', 'manufacturer': 'Apple Inc.', 'serialnumber': 'C0PPP011DV2R', 'protovers': '1.1', 'srcvers': '366.0', 'pi': 'ee5e381d-b729-4298-b883-8a9185ff38a8', 'gid': 'C87AD4D2-8E40-49A6-8C0F-DF0D3FE982BC', 'gcgl': '1', 'isgroupleader': '0', 'pk': '47194e7cf766969a590ca17ebd4a4c9840cd5f48a7d2c17066a837290ea65eef'}) 2021-09-22 14:44:48 ERROR [root]: Could not find any Apple TV on current network

`

postlund commented 3 years ago

The id you are using comes from one of the services you are not scanning for, that's why it doesn't work. Run atvremote --scan-protocols airplay scan and pick the identifier you get from your device there. After that it should work. Alternatively you may use -a <ip address> instead.

martinorob commented 3 years ago

Very strange…

atvremote --scan-protocols airplay scan                                                       3 ⨯
Scan Results
========================================
       Name: AppleTV
   Model/SW: Gen4 Unknown OS 15.0
    Address: 192.168.3.52
        MAC: C8:69:CD:6E:43:86
 Deep Sleep: False
Identifiers:
 - C8:69:CD:6E:43:86
Services:
 - Protocol: AirPlay, Port: 7000, Credentials: None

       Name: TV
   Model/SW: AirPortExpressGen2 AirPortOS
    Address: 192.168.3.27
        MAC: 00:F7:6F:D4:4B:0A
 Deep Sleep: False
Identifiers:
 - 00:F7:6F:D4:4B:0A
Services:
 - Protocol: AirPlay, Port: 7000, Credentials: None

So my apple tv ID is “c8:69:CD:6E:43:86”

so i successful pair with

atvremote --id C8:69:CD:6E:43:86  --protocol airplay pair                                     3 ⨯
Enter PIN on screen: 7682
Pairing seems to have succeeded, yey!
You may now use these credentials: BC257A8A4A7E9C10:F54A09E3DD677BE490A7C03AD3213545A945C2D1F54EB72096C3EBD045A4C372

and then try to play

atvremote --id C8:69:CD:6E:43:86 --airplay-credentials "BC257A8A4A7E9C10:F54A09E3DD677BE490A7C03AD3213545A945C2D1F54EB72096C3EBD045A4C372" --scan-protocols airplay play
NOTE: Push updates are not supported in this configuration
2021-09-22 15:37:04 ERROR [root]: Command 'play' is not supported by device
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/pyatv/scripts/atvremote.py", line 690, in _exec_command
    value = await tmp(*args)
  File "/usr/local/lib/python3.9/site-packages/pyatv/support/facade.py", line 94, in play
    return await self.relay("play")()
  File "/usr/local/lib/python3.9/site-packages/pyatv/support/relayer.py", line 75, in relay
    instance = self._find_instance(target, priority or self._priorities)
  File "/usr/local/lib/python3.9/site-packages/pyatv/support/relayer.py", line 97, in _find_instance
    raise exceptions.NotSupportedError(f"{target} is not supported")
pyatv.exceptions.NotSupportedError: play is not supported

Thanks for your patience… 😊

postlund commented 3 years ago

No worries! I don't think you have the latest version of pyatv, you should double check that. Version 0.9.0 is out now, so you can upgrade to that with pip.

martinorob commented 3 years ago

YEEEEEE NOW WORKS! Well, it works with airplay but if I try with the companion protocol the problem persist..

atvremote scan --protocol companion

Scan Results
========================================
       Name: AppleTV
   Model/SW: Gen4 tvOS 15.0 build 19J346
    Address: 192.168.3.52
        MAC: C8:69:CD:6E:43:86
 Deep Sleep: False
Identifiers:
 - C8:69:CD:6E:43:86
 - 8CD254F3-CA9C-4B4C-AEBD-113FC050DD45
 - C869CD6E4386
Services:
 - Protocol: AirPlay, Port: 7000, Credentials: None, Requires Password: False, Password: None, Pairing: Mandatory
 - Protocol: Companion, Port: 49153, Credentials: None, Requires Password: False, Password: None, Pairing: Mandatory
 - Protocol: MRP, Port: 49152, Credentials: None, Requires Password: False, Password: None, Pairing: Optional
 - Protocol: RAOP, Port: 7000, Credentials: None, Requires Password: False, Password: None, Pairing: Mandatory

       Name: TV
   Model/SW: AirPortExpressGen2 AirPortOS 7.8.1
    Address: 192.168.3.27
        MAC: 00:F7:6F:D4:4B:0A
 Deep Sleep: False
Identifiers:
 - 00:F7:6F:D4:4B:0A
 - 00F76FD44B0A
Services:
 - Protocol: AirPlay, Port: 7000, Credentials: None, Requires Password: False, Password: None, Pairing: NotNeeded
 - Protocol: RAOP, Port: 7000, Credentials: None, Requires Password: False, Password: None, Pairing: NotNeeded

atvremote --id C8:69:CD:6E:43:86 --protocol companion pair

Enter PIN on screen: 3942 Pairing seems to have succeeded, yey! You may now use these credentials: db120e921609b11ae66fb2ee2b4aa9f6adaf3e2e480a18e3d8356b29b7745f41:9152232cb06270a4a88e568030ed4538a6d68ae99353e374d5102b9dd76596c1:46383142303836342d453236422d343042412d424232432d313633454435463230304245:34376165663733652d303466622d346538322d383134662d666233386663386538363534

atvremote --address 192.168.3.52 --id C8:69:CD:6E:43:86 --companion-credentials "db120e921609b11ae66fb2ee2b4aa9f6adaf3e2e480a18e3d8356b29b7745f41:9152232cb06270a4a88e568030ed4538a6d68ae99353e374d5102b9dd76596c1:46383142303836342d453236422d343042412d424232432d313633454435463230304245:34376165663733652d303466622d346538322d383134662d666233386663386538363534" --scan-protocols companion device_info --debug

2021-09-22 16:40:25 DEBUG [pyatv.support.net]: Binding on *:5353
2021-09-22 16:40:25 DEBUG [pyatv.support.net]: Binding on 127.0.0.1:0
2021-09-22 16:40:25 DEBUG [pyatv.support.net]: Binding on 192.168.3.80:0
2021-09-22 16:40:28 DEBUG [pyatv.core.scan]: Auto-discovered vMac at 192.168.3.80:49300 via Protocol.Companion ({'rpba': '0F:DA:33:87:8A:22', 'rpad': '0962d1573994', 'rpfl': '0x20000', 'rphn': '3c0f7f90dd47', 'rpmac': '0', 'rpvr': '260.3'})
2021-09-22 16:40:28 DEBUG [pyatv.core.scan]: Auto-discovered AppleTV at 192.168.3.52:49153 via Protocol.Companion ({'rpmac': '1', 'rphn': '305285bdaf4d', 'rpfl': '0x36782', 'rpha': 'b0ce76eb85f0', 'rpmd': 'AppleTV5,3', 'rpvr': '300.66', 'rpad': 'fe26ead7e02a', 'rphi': 'a05005f4b704', 'rpba': 'EF:F2:B2:C7:65:BE', 'rpmrtid': 'F81B0864-E26B-40BA-BB2C-163ED5F200BE'})
2021-09-22 16:40:28 DEBUG [pyatv.core.scan]: Auto-discovered iPad at 192.168.3.196:49408 via Protocol.Companion ({'rpmac': '0', 'rphn': '1b0ae5fbd527', 'rpfl': '0x30000', 'rpha': '47fe8888a200', 'rpvr': '300.66', 'rpad': '873ed32f249d', 'rphi': 'b4ae58f76abb', 'rpba': '50:DA:43:EA:54:58'})
2021-09-22 16:40:28 DEBUG [pyatv.core.scan]: Auto-discovered iMartinoPadPro at 192.168.3.100:49471 via Protocol.Companion ({'rpmac': '0', 'rphn': '1dec4913f32c', 'rpfl': '0x30000', 'rpha': 'eaed4a11bb5f', 'rpvr': '300.66', 'rpad': '4f56e4b1479c', 'rphi': 'eeefbd4b7ef6', 'rpba': '3C:C2:97:B7:D9:2B'})
2021-09-22 16:40:28 DEBUG [pyatv.core.scan]: Auto-discovered MacBookPro at 192.168.3.98:64612 via Protocol.Companion ({'rpmac': '0', 'rphn': 'a3be43fb4dcb', 'rpfl': '0x20000', 'rpha': '0a8a1b4a2537', 'rpvr': '260.3', 'rpad': '1c390a4466cb', 'rphi': '98cdafa23b7a', 'rpba': 'F1:09:5D:F9:62:18'})
2021-09-22 16:40:28 ERROR [pyatv.scripts.atvremote]: Could not find any Apple TV on current network
martinorob commented 3 years ago

if I write a simple command, seems that credentials ar incorrect and Apple TV give me another PIN

atvremote --id C8:69:CD:6E:43:86 --companion-credentials "db120e921609b11ae66fb2ee2b4aa9f6adaf3e2e480a18e3d8356b29b7745f41:9152232cb06270a4a88e568030ed4538a6d68ae99353e374d5102b9dd76596c1:46383142303836342d453236422d343042412d424232432d313633454435463230304245:34376165663733652d303466622d346538322d383134662d666233386663386538363534" select delay=1000 left

`2021-09-22 16:54:02 WARNING [pyatv.protocols.airplay]: Failed to set up remote control channel: HTTP/1.1 method POST failed with code 470: Connection Authorization Required Traceback (most recent call last): File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/locks.py", line 413, in acquire await fut asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/tasks.py", line 492, in wait_for fut.result() asyncio.exceptions.CancelledError

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

Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/pyatv/scripts/atvremote.py", line 700, in _run_application return await cli_handler(loop) File "/usr/local/lib/python3.9/site-packages/pyatv/scripts/atvremote.py", line 494, in cli_handler return await _handle_commands(args, config, loop) File "/usr/local/lib/python3.9/site-packages/pyatv/scripts/atvremote.py", line 585, in _handle_commands atv = await connect(config, loop, protocol=args.protocol) File "/usr/local/lib/python3.9/site-packages/pyatv/init.py", line 96, in connect await atv.connect() File "/usr/local/lib/python3.9/site-packages/pyatv/core/facade.py", line 425, in connect if await setup_data.connect(): File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/mrp/init.py", line 870, in _connect await protocol.start() File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/mrp/protocol.py", line 134, in start self.device_info = await self.send_and_receive(msg) File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/mrp/protocol.py", line 234, in send_and_receive return await self._receive(identifier, timeout) File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/mrp/protocol.py", line 242, in _receive await asyncio.wait_for(semaphore.acquire(), timeout) File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/tasks.py", line 494, in wait_for raise exceptions.TimeoutError() from exc asyncio.exceptions.TimeoutError

An error occurred, full stack trace above `

postlund commented 3 years ago

You need to provide credentials for both protocols at the same time.

martinorob commented 3 years ago

Thank you!