home-assistant-libs / pychromecast

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

pychromecast.get_chromecasts() failing and not connecting #247

Open vajonam opened 6 years ago

vajonam commented 6 years ago

hi there,

i am not sure when this broke, but this used to work, not sure which update or change broke this.

Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> import pychromecast
>>> chromecasts = pychromecast.get_chromecasts()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pychromecast/__init__.py", line 75, in get_chromecasts
    blocking=blocking))
  File "/usr/local/lib/python2.7/dist-packages/pychromecast/__init__.py", line 42, in _get_chromecast_from_host
    blocking=blocking)
  File "/usr/local/lib/python2.7/dist-packages/pychromecast/__init__.py", line 169, in __init__
    blocking=blocking)
  File "/usr/local/lib/python2.7/dist-packages/pychromecast/socket_client.py", line 208, in __init__
    self.initialize_connection()
  File "/usr/local/lib/python2.7/dist-packages/pychromecast/socket_client.py", line 244, in initialize_connection
    self.socket.connect((self.host, self.port))
  File "/usr/lib/python2.7/socket.py", line 228, in meth
    return getattr(self._sock,name)(*args)
socket.timeout: timed out

Not sure what I am missing or changes. this not being done from inside a docker container but I have tried this on machines without docker installed at all.

dtmulc commented 5 years ago

Getting a similar problem. Did you have any luck getting this to work?

vajonam commented 5 years ago

This is a problem when you have docker or other network adapters, the discovery doesn't work correctly.

I got around it by specifying the IP of my chromecast which I know has dhcp reservation.

#!/usr/bin/python3

import sys
import logging

import pychromecast

cast = pychromecast.Chromecast('192.168.100.27')
cast.wait();

mc = cast.media_controller
mc.play_media('http://someurl.com/foo/my.mp3', 'audio/mp3')
mc.block_until_active()
mc.play()
jcoutu-va commented 5 years ago

I'm also seeing this on my network where we have a Jamboard. get_chromcasts() hangs and fails, but discover_chromecasts() works.