question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

520 RTSP error when trying to use TTS

See original GitHub issue

Describe the bug

I’m using the 3.3.1 beta with HomeAssistant 2022.2 and a Nabu Casa subscription (so using their TTS backend)

Individually, the cloud TTS and the appletv module both seem to work, but when I try to use the TTS feature of the appletv module to speak some text via a homepod or appletv, I get an error that doesn’t mean anything obvious to me. The TV pairing process had three separate PINs, the Homepod pairing process didn’t. I don’t know if that’s normal or not.

Error log



Logger: homeassistant.helpers.script.websocket_api_script
Source: custom_components/apple_tv/media_player.py:292
Integration: Apple TV
First occurred: February 2, 2022, 11:59:27 PM (2 occurrences)
Last logged: 12:03:55 AM
websocket_api script: Error executing script. Unexpected error for call_service at pos 1: RTSP/1.0 method SETUP failed with code 520: Origin Error

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 372, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 575, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1630, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1667, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/components/tts/__init__.py", line 205, in async_say_handle
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1630, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1667, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 668, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 921, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 705, in _handle_entity_call
    await result
  File "/config/custom_components/apple_tv/media_player.py", line 292, 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 352, in stream_file
    await client.initialize(self.core.service.properties)
  File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/raop/raop.py", line 457, in initialize
    await self._setup_session()
  File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/raop/raop.py", line 486, in _setup_session
    resp = await self.rtsp.setup(
  File "/usr/local/lib/python3.9/site-packages/pyatv/support/rtsp.py", line 175, in setup
    return await self.exchange("SETUP", headers=headers, body=body)
  File "/usr/local/lib/python3.9/site-packages/pyatv/support/rtsp.py", line 258, in exchange
    resp = await self.connection.send_and_receive(
  File "/usr/local/lib/python3.9/site-packages/pyatv/support/http.py", line 412, in send_and_receive
    raise exceptions.HttpError(
pyatv.exceptions.HttpError: RTSP/1.0 method SETUP failed with code 520: Origin Error

How to reproduce the bug?

Pick a supported homepod or appletv device, and attempt to use the Nabu Casa text to speech.

What is expected behavior?

Hearing the text to speech voice played by the device.

Operating System

Linux

Python

3.9

pyatv

0.10.0

Device

Apple TV 4k 15.3

Additional context

If there’s any other info I can provide, please let me know.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
tsrotencommented, Feb 8, 2022

I was able to fix this on my Raspberry Pi 4!

I successfully streamed to my HomePod Mini using atvremote on a different computer, which led me to look at my firewall configuration. Looking at my firewall logs on the RP4, I saw that the HomePod Mini was attempting to send UDP packets to ephemeral ports and they were being dropped. By opening up the ephemeral UDP port range (32768-65535) for traffic coming from the HomePod Mini, I was able to get the SETUP request to complete and the file to play successfully. It also fixed the same issue with my Apple TV.

0reactions
postlundcommented, Jun 28, 2022

I guess we can close this now!

Read more comments on GitHub >

github_iconTop Results From Across the Web

HomePod cannot play local media or tts · Issue #80419 - GitHub
The problem I set up my HomePod mini using the Apple TV integration ... RTSP/1.0 method SETUP failed with code 520: Origin Error...
Read more >
Reolink POE IP Camera Setup - Configuration
I have this errors. I belive the problem is the HA cant connect to the camera because the config is right or anyone...
Read more >
Help with RTSP on RLC-510A : r/reolinkcam - Reddit
Purchased a RLC-510A - can't get the RTSP stream to work at all - have a few other RLC-520 and they work fine......
Read more >
Failed to Connect the Camera via RTSP/RTMP
Solution: 1. Make sure the camera IP address, port, username, password are correct, please refer to the link here to confirm the URL...
Read more >
Troubleshoot RTSP/RTP playback - Wowza
This means that if UDP is unavailable for RTP playback, RTP over TCP won't work as a failover and your stream won't play....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found