klattimer / LGWebOSRemote

Command line webOS remote for LGTVs
MIT License
512 stars 99 forks source link

invalid syntax , ws4py and ws.send issue #14

Closed TommieNL closed 6 years ago

TommieNL commented 6 years ago

Hello! First of all, many thanks for your great work!

I tried to install & configure and ran into some troubles. A friend of mine came up with the following fixes. Not sure if i can help you with this but it helped my situation:

Device: Raspberry Pi 3 with Jessie Lite Python version 2.7.9

1. Syntax Error(s)

It started with syntax error's on lgtv.py. Maybe it had to do with the python version I used (?)

  File "lgtv.py", line 3
    from __future__ import print
                               ^
SyntaxError: invalid syntax

Fix: Edit in file: lgtv.py Comment: see first line and #.

from __future__ import print_function
import sys
import json
#from __future__ import print_function
from inspect import getargspec
from LGTV import LGTVScan, LGTVClient, getCommands

2. Module ws4py error(s)

After that we got the following error (see below). After some searching it seems to have something to do with the ws4py version and python 2.7.9 (not totally sure)

python lgtv.py auth 192.168.1.23
Traceback (most recent call last):
  File "lgtv.py", line 77, in <module>
    ws = LGTVClient(sys.argv[2])
  File "/home/pi/domoticz/scripts/lgtv/LGWebOSRemote/LGTV/__init__.py", line 214, in __init__
    super(LGTVClient, self).__init__('ws://' + self.__hostname + ':3000/', exclude_headers=["Origin"])
TypeError: __init__() got an unexpected keyword argument 'exclude_headers'

Fix: Got the latest version directly from git (seems to be newer then via pip) git clone https://github.com/Lawouach/WebSocket-for-Python.git

3. global name 'ws' is not defined error

And at last we got the 'global name 'ws' is not defined error' (see below)

 python lgtv.py auth 192.168.1.23
{"closing": {"reason": "Going away", "code": 1006}}
Exception in thread WebSocketClient:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "build/bdist.linux-armv7l/egg/ws4py/websocket.py", line 522, in run
    self.opened()
  File "/home/pi/domoticz/scripts/lgtv/LGWebOSRemote/LGTV/__init__.py", line 249, in opened
    ws.send(json.dumps(hello_data))
NameError: global name 'ws' is not defined

Fix: File: LGWebOSRemote/LGTV/init.py We fixed that one by changing ws.send to self.send

klattimer commented 6 years ago

Latest commit should fix everything, sorry, hacked a bit without testing fully.