home-assistant-libs / pychromecast

Library for Python 3 to communicate with the Google Chromecast.
MIT License
2.55k stars 380 forks source link

Unhandled exception in worker thread while trying to cast to a speakers group. #593

Open shenhab opened 2 years ago

shenhab commented 2 years ago
def execute_azan_on_device(fajr):
    if fajr:
        azan_url = 'https://www.gurutux.com/media/adhan_al_fajr.mp3'
        logging.debug('Adhan Al Fajr.')
    else:
        azan_url = 'https://www.gurutux.com/media/azan.mp3'
        logging.debug('Regular Adhan.')
    chromecast_devices, browser = pychromecast.get_listed_chromecasts(friendly_names = [google_home_device_name])
    casting_device = chromecast_devices[0]
    casting_device.logger.setLevel(30)
    casting_device.wait()
    browser.stop_discovery()
    cast_media_controller = casting_device.media_controller
    cast_media_controller.play_media(azan_url, 'audio/mp3')
    cast_media_controller.block_until_active()
WARNING:pychromecast.socket_client:[All Speakers(192.168.86.202):32197] Error communicating with socket, resetting connection
ERROR:pychromecast.socket_client:[All Speakers(192.168.86.202):32197] Error reading from socket.
ERROR:pychromecast.socket_client:[All Speakers(192.168.86.202):32197] Unhandled exception in worker thread, attempting reconnect
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/pychromecast/socket_client.py", line 538, in run
    if self.run_once(timeout=POLL_TIME_BLOCKING) == 1:
  File "/usr/local/lib/python3.9/dist-packages/pychromecast/socket_client.py", line 561, in run_once
    if not self._check_connection():
  File "/usr/local/lib/python3.9/dist-packages/pychromecast/socket_client.py", line 690, in _check_connection
    self.initialize_connection()
  File "/usr/local/lib/python3.9/dist-packages/pychromecast/socket_client.py", line 295, in initialize_connection
    host, port, service_info = get_host_from_service(
  File "/usr/local/lib/python3.9/dist-packages/pychromecast/dial.py", line 38, in get_host_from_service
diegobill commented 1 year ago

@gurutux , is the problem fixed with your commit above?

shenhab commented 1 year ago

Removing Stop discovery was just a work around, I am not really sure if the actual problem was solved or not.