home-assistant-libs / pychromecast

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

Connection failure #78

Open tim-devel opened 8 years ago

tim-devel commented 8 years ago

Hi,

I am using pychromecast with Home Assistant. I leave my Chromecast attached to the power permanently so I can use it to wake up my TV remotely via home assistant. Pychromecast connects to my Chromecast perfectly well when I first plug it in but after 12-24 hours uptime I start getting the error below. I can still cast media to the Chromecast from my phone but pychromecast is unable to connect. The only way to work around this error is to power cycle the Chromecast.

Sorry but I am not sure what more I can do to debug this error. I have detailed my set up below:

Pychromecast version 0.7.1 (and git clone from github) Python version 2.7.9 & 3.4.2 Raspberry Pi v2 (up to date Raspbian Jessie) Chromecast 1 - Firmware 1.17.46278

$ python example.py --show-debug
INFO:pychromecast:Querying device status
INFO:urllib3.connectionpool:Starting new HTTP connection (1): 192.168.0.4
DEBUG:urllib3.connectionpool:"GET /ssdp/device-desc.xml HTTP/1.1" 200 1092
ERROR:pychromecast.socket_client:Failed to connect, retrying in 5.000000s
Traceback (most recent call last):
  File "/home/pi/git/pychromecast/pychromecast/socket_client.py", line 233, in initialize_connection
    self.socket.connect((self.host, self.port))
  File "/usr/lib/python2.7/ssl.py", line 824, in connect
    self._real_connect(addr, False)
  File "/usr/lib/python2.7/ssl.py", line 815, in _real_connect
    self.do_handshake()
  File "/usr/lib/python2.7/ssl.py", line 788, in do_handshake
    self._sslobj.do_handshake()
SSLEOFError: EOF occurred in violation of protocol (_ssl.c:581)
DEBUG:pychromecast.socket_client:Failed to connect, retrying in 5.000000s
DEBUG:pychromecast.socket_client:Failed to connect, retrying in 5.000000s
DEBUG:pychromecast.socket_client:Failed to connect, retrying in 5.000000s
DEBUG:pychromecast.socket_client:Failed to connect, retrying in 5.000000s
^CTraceback (most recent call last):
  File "example.py", line 16, in <module>
    cast = pychromecast.get_chromecast()
  File "/home/pi/git/pychromecast/pychromecast/__init__.py", line 162, in get_chromecast
    results = _get_all_chromecasts(tries, retry_wait)
  File "/home/pi/git/pychromecast/pychromecast/__init__.py", line 56, in _get_all_chromecasts
    retry_wait=retry_wait))
  File "/home/pi/git/pychromecast/pychromecast/__init__.py", line 251, in __init__
    tries=tries, timeout=timeout, retry_wait=retry_wait)
  File "/home/pi/git/pychromecast/pychromecast/socket_client.py", line 197, in __init__
    self.initialize_connection()
  File "/home/pi/git/pychromecast/pychromecast/socket_client.py", line 259, in initialize_connection
    time.sleep(self.retry_wait)
KeyboardInterrupt
Exception AttributeError: "'Chromecast' object has no attribute 'socket_client'" in <bound method Chromecast.__del__ of Chromecast('192.168.0.4', port=8009, device=DeviceStatus(friendly_name=u'Chromecast4315', model_name=u'Chromecast', manufacturer=u'Google Inc.', api_version=(1, 0), uuid=UUID('REDACTED'), cast_type='cast'))> ignored
tim-devel commented 8 years ago

Anyone have any thoughts on this one?

cburmeister commented 8 years ago

I'm getting the same error but it seems to happen after invoking pychromecast.Chromecast(ip) a handful of times...

cburmeister commented 8 years ago

@timstanley1985 I fixed this error with Chromecast.disconnect() FWIW

minscof commented 8 years ago

I have the same problem.

is it possible to add Chromecast.disconnect() in the socket_client.py itself ?