postlund / pyatv

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

TimeoutError: no response to CSeq 0 #1576

Open malosaa opened 2 years ago

malosaa commented 2 years ago

Describe the bug

Using home assistant last version. 2021.12.7

Well when i go to the device and test the tts, i get this error. I don't even know why

regards

Error log

Logger: homeassistant.components.websocket_api.http.connection
Source: custom_components/apple_tv/media_player.py:286
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 12:15:12 (3 occurrences)
Last logged: 12:20:15

[140632704872848] no response to CSeq 0 (/info)
[140632215484160] no response to CSeq 0 (/info)
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/asyncio/locks.py", line 226, in wait
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/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/support/rtsp.py", line 281, in exchange
    await asyncio.wait_for(self.requests[cseq][0].wait(), 4)
  File "/usr/local/lib/python3.9/asyncio/tasks.py", line 494, in wait_for
    raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError

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

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 185, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1495, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1530, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/components/tts/__init__.py", line 200, in async_say_handle
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1495, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1530, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 209, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 663, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 896, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 700, in _handle_entity_call
    await result
  File "/config/custom_components/apple_tv/media_player.py", line 286, in async_play_media
    await self.atv.stream.stream_file(media_id)
  File "/usr/local/lib/python3.9/site-packages/pyatv/core/facade.py", line 382, in stream_file
    await self.relay("stream_file")(file, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/raop/__init__.py", line 331, in stream_file
    await client.initialize(self.service.properties)
  File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/raop/raop.py", line 450, in initialize
    self._info.update(await self.rtsp.info())
  File "/usr/local/lib/python3.9/site-packages/pyatv/support/rtsp.py", line 98, in info
    device_info = await self.exchange("GET", "/info", allow_error=True)
  File "/usr/local/lib/python3.9/site-packages/pyatv/support/rtsp.py", line 284, in exchange
    raise TimeoutError(
TimeoutError: no response to CSeq 0 (/info)

How to reproduce the bug?

I don't know

What is expected behavior?

It should normally work.

Operating System

HASS OS 7.0

Python

Other

pyatv

0.9.8 v2.2.0 in hass

Device

Apple tv aircast device 3.0

Additional context

no

postlund commented 2 years ago

@malosaa I'm hoping that #1616 works, can you try that?

malosaa commented 2 years ago

@malosaa I'm hoping that #1616 works, can you try that? thanks,

if i'm correct it changed only 1 file, so i updated that one and get a time-out

$ atvremote -s 192.168.1.54 stream_file=https://www.myinstants.com/media/sounds/epic.mp3
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\asyncio\locks.py", line 226, in wait
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\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 "c:\users\31683\pyatv\pyatv\support\rtsp.py", line 286, in exchange
    await asyncio.wait_for(self.requests[cseq][0].wait(), 4)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\asyncio\tasks.py", line 494, in wait_for
    raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError

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

Traceback (most recent call last):
  File "c:\users\31683\pyatv\pyatv\scripts\atvremote.py", line 719, in _run_application
    return await cli_handler(loop)
  File "c:\users\31683\pyatv\pyatv\scripts\atvremote.py", line 513, in cli_handler
    return await _handle_commands(args, config, loop)
  File "c:\users\31683\pyatv\pyatv\scripts\atvremote.py", line 614, in _handle_commands
    ret = await _handle_device_command(args, cmd, atv, loop)
  File "c:\users\31683\pyatv\pyatv\scripts\atvremote.py", line 662, in _handle_device_command
    return await _exec_command(atv.stream, cmd, True, *cmd_args)
  File "c:\users\31683\pyatv\pyatv\scripts\atvremote.py", line 685, in _exec_command
    value = await tmp(*args)
  File "c:\users\31683\pyatv\pyatv\core\facade.py", line 382, in stream_file
    await self.relay("stream_file")(file, **kwargs)
  File "c:\users\31683\pyatv\pyatv\protocols\raop\__init__.py", line 348, in stream_file
    await client.initialize(self.core.service.properties)
  File "c:\users\31683\pyatv\pyatv\protocols\raop\raop.py", line 454, in initialize
    print("INFO:", await self.rtsp.exchange("GET", "/info"))
  File "c:\users\31683\pyatv\pyatv\support\rtsp.py", line 289, in exchange
    raise TimeoutError(
TimeoutError: no response to CSeq 0 (/info)

>>> An error occurred, full stack trace above
(venv)
postlund commented 2 years ago

That's so strange. Can you run it with --debug as well and paste the error and ten-or-so lines above it?

malosaa commented 2 years ago

That's so strange. Can you run it with --debug as well and paste the error and ten-or-so lines above it?

i'm really sorry for this late reply, my life is sometimes so busy.. its not professional from me not to give you a heads up while u try to help me.

My apology


$ atvremote --debug -s 192.168.1.54 stream_file=https://www.myinstants.com/media/sounds/epic.mp3
2022-01-31 16:25:58 DEBUG [pyatv.scripts]: Running with pyatv 0.9.8
2022-01-31 16:25:58 DEBUG [pyatv.support.knock]: Knocking at port 3689 on 192.168.1.54
2022-01-31 16:25:58 DEBUG [pyatv.support.knock]: Knocking at port 7000 on 192.168.1.54
2022-01-31 16:25:58 DEBUG [pyatv.support.knock]: Knocking at port 49152 on 192.168.1.54
2022-01-31 16:25:58 DEBUG [pyatv.support.knock]: Knocking at port 32498 on 192.168.1.54
2022-01-31 16:25:59 DEBUG [pyatv.core.scan]: Auto-discovered LivingroomSpeaker at 192.168.1.54:7000 via Protocol.AirPlay ({'deviceid': '56:E4:BD:D2:18:D3', 'features': '0x0A7FCE40', 'flags': '0x4', 'rmodel': 'EZAir1,1', 'model': 'AppleTV3,2', 'srcvers': '220.68', 'vv': '2', 'pk': '978bb5a35fa53037ff73b7b25994614a3c19896152031221ce2a91b2eed8be9a', 'pi': 'b08f5a79-db29-4384-b456-a4784d9e6055'})
2022-01-31 16:25:59 DEBUG [pyatv.core.scan]: Auto-discovered 56E4BDD218D3@LivingroomSpeaker at 192.168.1.54:47000 via Protocol.RAOP ({'cn': '0,1,3', 'da': 'true', 'et': '0,3,5', 'ft': '0x0A7FCE40', 'md': '0,1,2', 'tp': 'UDP', 'vn': '65537', 'vs': '220.68', 'rmodel': 'EZAir1,1', 'am': 'AppleTV3,2', 'vv': '2', 'sf': '0x4', 'pk': '978bb5a35fa53037ff73b7b25994614a3c19896152031221ce2a91b2eed8be9a'})
2022-01-31 16:25:59 INFO [pyatv.scripts.atvremote]: Auto-discovered LivingroomSpeaker at 192.168.1.54
2022-01-31 16:25:59 DEBUG [pyatv.core.facade]: Adding handler for protocol Protocol.AirPlay
2022-01-31 16:25:59 DEBUG [pyatv.protocols.airplay]: Remote control not supported by device
2022-01-31 16:25:59 DEBUG [pyatv.core.facade]: Adding handler for protocol Protocol.RAOP
2022-01-31 16:25:59 DEBUG [pyatv.core.facade]: Connecting to protocol: Protocol.AirPlay
2022-01-31 16:25:59 DEBUG [pyatv.core.facade]: Connected to protocol: Protocol.AirPlay
2022-01-31 16:25:59 DEBUG [pyatv.core.facade]: Connecting to protocol: Protocol.RAOP
2022-01-31 16:25:59 DEBUG [pyatv.core.facade]: Connected to protocol: Protocol.RAOP
2022-01-31 16:25:59 DEBUG [pyatv.core.facade]: Power management not supported by any protocols
2022-01-31 16:25:59 DEBUG [pyatv.core.facade]: Takeover (<class 'pyatv.interface.Audio'>, <class 'pyatv.interface.Metadata'>, <class 'pyatv.interface.PushUpdater'>, <class 'pyatv.interface.RemoteControl'>) by Protocol.RAOP
2022-01-31 16:25:59 DEBUG [pyatv.support.http]: Connected to 192.168.1.54
2022-01-31 16:25:59 DEBUG [pyatv.protocols.raop.raop]: Initializing RTSP with encryption=EncryptionType.FairPlaySAPv25|FairPlay|Unencrypted, metadata=MetadataType.Progress|Artwork|Text
2022-01-31 16:25:59 DEBUG [pyatv.protocols.raop.raop]: Update play settings to 44100/2/16bit
2022-01-31 16:25:59 DEBUG [pyatv.protocols.raop.raop]: Local ports: control=61219, timing=61220
2022-01-31 16:25:59 DEBUG [pyatv.support.http]: Sending RTSP/1.0 message: b'GET /info RTSP/1.0\r\nUser-Agent: AirPlay/540.31\r\nCSeq: 0\r\nDACP-ID: 472B827342FB2AA\r\nActive-Remote: 2520036651\r\nClient-Instance: 472B827342FB2AA\r\n\r\n'
2022-01-31 16:25:59 DEBUG [pyatv.support.http]: Received: b'RTSP/1.0 200 OK\r\nDate: Mon, 05 Jan 1970 03:21:58 +0000\r\nContent-Length: 819\r\nContent-Type: application/x-apple-binary-plist\r\nServer: AirTunes/220.68\r\n\r\n'
2022-01-31 16:25:59 DEBUG [pyatv.support.http]: Not enough data to decode message
2022-01-31 16:25:59 DEBUG [pyatv.support.http]: Received: b'bplist00\xdf\x10\x0f\x01\x03\x05\x07\t\x0b\x0c\x0e\x10\x12\x13\x15\x1f(*\x02\x04\x06\x08\n\n\r\x0f\x11\x11\x14\x16 )+RpkO\x10 \x97\x8b\xb5\xa3_\xa507\xffs\xb7\xb2Y\x94aJ<\x19\x89aR\x03\x12!\xce*\x91\xb2\xee\xd8\xbe\x9a\xa0TnameXApple TVRvv\x10\x02[statusFlags\x10\x04_\x10\x11keepAliveLowPower\x10\x01_\x10\x18keepAliveSendStatsAsBodyRpi_\x10$b08f5a79-db29-4384-b456-a4784d9e6055]sourceVersionV220.68XdeviceID_\x10\x1156:E4:BD:D2:18:D3ZmacAddressUmodelZAppleTV3,2\\audioFormats\xa2\x17\x1d\xd3\x18\x1a\x1b\x19\x19\x1c_\x10\x11audioInputFormats\x12\x03\xff\xff\xfc_\x10\x12audioOutputFormatsTtype\x10d\xd3\x18\x1a\x1b\x19\x19\x1e\x10e^audioLatencies\xa2!\'\xd4"$&\x1b#%%\x1cYaudioTypeWdefault_\x10\x12inputLatencyMicros\x08_\x10\x13outputLatencyMicros\xd4"$&\x1b#%%\x1eXfeatures\x12\n\x7f\xce@Xdisplays\xa1,\xdb-/123456(9:.0%%%0.78%;Vheight\x11\x02\xd0Uwidth\x11\x05\x00Xrotation]widthPhysical^heightPhysical[widthPixels\\heightPixels[refreshRate\x10\x1e\x10\x0e[overscannedTuuid_\x10$2684e1cf-4a70-4559-8658-9bef9ae21729\x00\x08\x00)\x00,\x00P\x00U\x00^\x00a\x00c\x00o\x00q\x00\x85\x00\x87\x00\xa2\x00\xa5\x00\xcc\x00\xda\x00\xe1\x00\xea\x00\xfe\x01\t\x01\x0f\x01\x1a\x01\'\x01*\x011\x01E\x01J\x01_\x01d\x01f\x01m\x01o\x01~\x01\x81\x01\x8a\x01\x94\x01\x9c\x01\xb1\x01\xb2\x01\xc8\x01\xd1\x01\xda\x01\xdf\x01\xe8\x01\xea\x02\x01\x02\x08\x02\x0b\x02\x11\x02\x14\x02\x1d\x02+\x02:\x02F\x02S\x02_\x02a\x02c\x02o\x02t\x00\x00\x00\x00\x00\x00\x02\x01\x00\x00\x00\x00\x00\x00\x00<\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x9b'
2022-01-31 16:25:59 DEBUG [pyatv.support.http]: Got RTSP response: HttpResponse(protocol='RTSP', version='1.0', code=200, message='OK', headers={'date': 'Mon, 05 Jan 1970 03:21:58 +0000', 'content-length': '819', 'content-type': 'application/x-apple-binary-plist', 'server': 'AirTunes/220.68'}, body=b'bplist00\xdf\x10\x0f\x01\x03\x05\x07\t\x0b\x0c\x0e\x10\x12\x13\x15\x1f(*\x02\x04\x06\x08\n\n\r\x0f\x11\x11\x14\x16 )+RpkO\x10 \x97\x8b\xb5\xa3_\xa507\xffs\xb7\xb2Y\x94aJ<\x19\x89aR\x03\x12!\xce*\x91\xb2\xee\xd8\xbe\x9a\xa0TnameXApple TVRvv\x10\x02[statusFlags\x10\x04_\x10\x11keepAliveLowPower\x10\x01_\x10\x18keepAliveSendStatsAsBodyRpi_\x10$b08f5a79-db29-4384-b456-a4784d9e6055]sourceVersionV220.68XdeviceID_\x10\x1156:E4:BD:D2:18:D3ZmacAddressUmodelZAppleTV3,2\\audioFormats\xa2\x17\x1d\xd3\x18\x1a\x1b\x19\x19\x1c_\x10\x11audioInputFormats\x12\x03\xff\xff\xfc_\x10\x12audioOutputFormatsTtype\x10d\xd3\x18\x1a\x1b\x19\x19\x1e\x10e^audioLatencies\xa2!\'\xd4"$&\x1b#%%\x1cYaudioTypeWdefault_\x10\x12inputLatencyMicros\x08_\x10\x13outputLatencyMicros\xd4"$&\x1b#%%\x1eXfeatures\x12\n\x7f\xce@Xdisplays\xa1,\xdb-/123456(9:.0%%%0.78%;Vheight\x11\x02\xd0Uwidth\x11\x05\x00Xrotation]widthPhysical^heightPhysical[widthPixels\\heightPixels[refreshRate\x10\x1e\x10\x0e[overscannedTuuid_\x10$2684e1cf-4a70-4559-8658-9bef9ae21729\x00\x08\x00)\x00,\x00P\x00U\x00^\x00a\x00c\x00o\x00q\x00\x85\x00\x87\x00\xa2\x00\xa5\x00\xcc\x00\xda\x00\xe1\x00\xea\x00\xfe\x01\t\x01\x0f\x01\x1a\x01\'\x01*\x011\x01E\x01J\x01_\x01d\x01f\x01m\x01o\x01~\x01\x81\x01\x8a\x01\x94\x01\x9c\x01\xb1\x01\xb2\x01\xc8\x01\xd1\x01\xda\x01\xdf\x01\xe8\x01\xea\x02\x01\x02\x08\x02\x0b\x02\x11\x02\x14\x02\x1d\x02+\x02:\x02F\x02S\x02_\x02a\x02c\x02o\x02t\x00\x00\x00\x00\x00\x00\x02\x01\x00\x00\x00\x00\x00\x00\x00<\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x9b'):
2022-01-31 16:26:03 DEBUG [pyatv.core.facade]: Release (<class 'pyatv.interface.Audio'>, <class 'pyatv.interface.Metadata'>, <class 'pyatv.interface.PushUpdater'>, <class 'pyatv.interface.RemoteControl'>) by Protocol.RAOP
2022-01-31 16:26:03 DEBUG [pyatv.scripts.atvremote]: Waiting for 0 remaining tasks
2022-01-31 16:26:03 DEBUG [pyatv.protocols.raop.raop]: Control connection lost (None)
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\asyncio\locks.py", line 226, in wait
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\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 "c:\users\31683\pyatv\pyatv\support\rtsp.py", line 286, in exchange
    await asyncio.wait_for(self.requests[cseq][0].wait(), 4)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\asyncio\tasks.py", line 494, in wait_for
    raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError

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

Traceback (most recent call last):
  File "c:\users\31683\pyatv\pyatv\scripts\atvremote.py", line 719, in _run_application
    return await cli_handler(loop)
  File "c:\users\31683\pyatv\pyatv\scripts\atvremote.py", line 513, in cli_handler
    return await _handle_commands(args, config, loop)
  File "c:\users\31683\pyatv\pyatv\scripts\atvremote.py", line 614, in _handle_commands
    ret = await _handle_device_command(args, cmd, atv, loop)
  File "c:\users\31683\pyatv\pyatv\scripts\atvremote.py", line 662, in _handle_device_command
    return await _exec_command(atv.stream, cmd, True, *cmd_args)
  File "c:\users\31683\pyatv\pyatv\scripts\atvremote.py", line 685, in _exec_command
    value = await tmp(*args)
  File "c:\users\31683\pyatv\pyatv\core\facade.py", line 382, in stream_file
    await self.relay("stream_file")(file, **kwargs)
  File "c:\users\31683\pyatv\pyatv\protocols\raop\__init__.py", line 348, in stream_file
    await client.initialize(self.core.service.properties)
  File "c:\users\31683\pyatv\pyatv\protocols\raop\raop.py", line 454, in initialize
    print("INFO:", await self.rtsp.exchange("GET", "/info"))
  File "c:\users\31683\pyatv\pyatv\support\rtsp.py", line 289, in exchange
    raise TimeoutError(
TimeoutError: no response to CSeq 0 (/info)

>>> An error occurred, full stack trace above
(venv)
postlund commented 2 years ago

No worries, I've been busy myself (and had a case of the stomach flu) so I've been pretty distant myself... That output proved pretty helpful! The request actually seems to work, the response is here:

2022-01-31 16:25:59 DEBUG [pyatv.support.http]: Got RTSP response: HttpResponse(protocol='RTSP', version='1.0', code=200, message='OK', headers={'date': 'Mon, 05 Jan 1970 03:21:58 +0000', 'content-length': '819', 'content-type': 'application/x-apple-binary-plist', 'server': 'AirTunes/220.68'}, body=b'bplist00...

So, to the problem... RTSP is based on the same protocol logic as HTTP but supports asynchronous requests using a special header called CSeq. If a request contains CSeq in the header section (with a particular integer), the response will contain the same CSeq header so the sender can match it with the correct request. This feature is rarely (never?) used as far as I know, but all receivers seems to support it. Except for the one you have. I use CSeq to match requests/responses in pyatv, but in your case the response does not contain that header and that is why the error is no response to CSeq 0.

I can make a work around for this by sending a request (like OPTIONS) that includes a CSeq and verify if I get CSeq back. If I don't, I fall back to not use CSeq at all. It needs some work, but certainly not impossible to accomplish.

malosaa commented 2 years ago

hope you feel better now, Well good news that there has been a work around for it, so it maybe gonna work. It does indeed respond.

malosaa commented 2 years ago

@postlund

we can close this issue, i got rid of this retarded device haha. It was also disconnecting many times.

I buyed google speaker and works great.

postlund commented 2 years ago

I still want to fix the problem as it is a bug, so I'll leave it open. You don't have to do anything more of course.

malosaa commented 2 years ago

true, ok no worries, thanks anyway for assisting :)

obertugo commented 5 months ago

Hello, I know it's been a while, but I think I have the same problem and also with an ez-mira device. The log is practically identical, when I try to play some local content, from my hard drive. But, it does work perfectly when playing online content from a url. I would like to know if it is possible to correct the lack of playback from files on my PC.

I am running voidlinux-i686...

I look forward to your responses and thank you very much in advance.