LGWebOSRemote
LGWebOSRemote copied to clipboard
SSL by default, failover to plain
Some devices will support SSL, some will not, of those which do, some may support plaintext. It makes most sense for us to take the most secure option and failover to the least secure option.
One slight complication with this for now, is that ws4py is using ssl.wrap_socket when SSL is enabled, which was marked as deprecated in Python 3.7 and removed in Python 3.12, so it makes lgtv fail like this:
~ % lgtv --ssl swInfo
Traceback (most recent call last):
File "/Users/jeppe/.local/bin/lgtv", line 33, in <module>
sys.exit(load_entry_point('LGTV', 'console_scripts', 'lgtv')())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/jeppe/my-git/LGWebOSRemote/LGTV/__init__.py", line 191, in main
ws.connect()
File "/Users/jeppe/.local/pipx/venvs/lgtv/lib/python3.12/site-packages/ws4py/client/__init__.py", line 214, in connect
self.sock = ssl.wrap_socket(self.sock, **self.ssl_options)
^^^^^^^^^^^^^^^
AttributeError: module 'ssl' has no attribute 'wrap_socket'
There's a fix for ws4py in https://github.com/Lawouach/WebSocket-for-Python/pull/283, but I wonder if it might otherwise be worth looking at migrating to another websocket library that is kept more up to date, as ws4py hasn't had a release since 2018?
@Tenzer ws4py was the only one I found that I could make work - specifically, I had to exclude default headers in order to make it work back on webOS 2.x IIRC. You'll find this in the code where exclude_headers=['Origin'] IIRC, which was always being sent by ws4py (it IS part of the spec, so you can't blame them).
This is in itself a bit of a hack, and was likely due to a bug in the webOS web socket server libraries and may now have been fixed.
Is there any workaround with this?
I tried @cmer 's suggestion of rolling back to Python 3.6 but got the following error:
% brew install [email protected] Warning: No available formula with the name "[email protected]". Did you mean [email protected], [email protected], [email protected], [email protected], [email protected], [email protected] or python-yq? ==> Searching for similarly named formulae and casks... ==> Formulae [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] python-yq
The problem only exists with Python 3.12, so try version 3.11 for now.
The problem only exists with Python 3.12, so try version 3.11 for now.
That worked! Thank you!
I'm sorry, but the real fix is https://github.com/Lawouach/WebSocket-for-Python/pull/283/files/1d9ffff3beb71553c85e846a1b828ec7d890e751
Not all of us can afford to use ancient versions of python.