klattimer/LGWebOSRemote

Connection reset by peer error?

tonycassara opened this issue ยท 15 comments

Hey I started getting this error after updating to the latest software version for my OLED C2 03.30.16:

DEBUG:getmac:Initializing 'ip4' method cache (platform: 'darwin')
DEBUG:getmac:Finished initializing 'ip4' method cache
DEBUG:getmac:Raw MAC found: **:**:**:**:**:**
Traceback (most recent call last):
  File "/opt/lgtv-venv/bin/lgtv", line 33, in <module>
    sys.exit(load_entry_point('LGTV==0.3', 'console_scripts', 'lgtv')())
  File "/opt/lgtv-venv/lib/python3.10/site-packages/LGTV/__init__.py", line 138, in main
    ws.connect()
  File "/opt/lgtv-venv/lib/python3.10/site-packages/ws4py/client/__init__.py", line 224, in connect
    bytes = self.sock.recv(128)
ConnectionResetError: [Errno 54] Connection reset by peer

Sorry I'm not very familiar with Python I'm not sure what's going on but it looks specific to the ws4py package?

I obfuscated the MAC address for security reasons.

I somehow have this package installed twice, in another directory I get a more verbose error message:

DEBUG:getmac:Could not find file: '/proc/net/arp'
DEBUG:getmac:Raw MAC found: **:**:**:**:**:**
DEBUG:getmac:Length of MAC **:**:**:**:**:** is 16, padding single-character octets with zeros
Traceback (most recent call last):
  File "/Users/tcassara/opt/lgtv/bin/lgtv", line 33, in <module>
    sys.exit(load_entry_point('LGTV==0.3', 'console_scripts', 'lgtv')())
  File "/Users/tcassara/opt/lgtv/lib/python3.9/site-packages/LGTV/__init__.py", line 138, in main
    ws.connect()
  File "/Users/tcassara/opt/lgtv/lib/python3.9/site-packages/ws4py/client/__init__.py", line 224, in connect
    bytes = self.sock.recv(128)
ConnectionResetError: [Errno 54] Connection reset by peer

Seeing the exact same behavior following this update on the C2.

Sorry guys the TV I used to develop this no longer gets updates so I'm not able to debug it for you. I'll happily approve a PR if I get one but don't break backward compatibility.

@klattimer thanks for the update... your app is used by cmer's https://github.com/cmer/lg-tv-control-macos/ project and the LG C2 just broke from today's patch, so hopefully some Python experts will come along soon ๐Ÿ‘

So from what I can tell the MAC address is parsing out leading zeros in the mac address so something like 01:24:45:34:35:1b becomes 1:24:45:34:35:1b. I wonder if we're just failing to parse correctly somewhere.

I opened an issue on the LG TV control macOS GitHub in case someone there wants to take a stab at correcting this.

I don't think it's related to MAC address. During auth step, it connects to the websocket via IP address, and somehow ws.connect() gets rejected by the TV.
IIUC MAC address is only used in wake-on-lan packet later on.

FWIW, my MAC address doesn't involve leading 0, and still failed.

Here is a commit in another project for windows that updates to support the newest TV firmware which should be helpful for updating this package. That commit contains some other changes but from a quick look it seems like there's a new connection method.

Also found that the bscpylgtv project is updated as well. SSL needs to be used for the connection as implemented here.

SSL is now required for connection to newer firmware devices at port 3001, pull request added.

@burnee 's PR here: #109

Unfortunately this did not fix my isssue :(

you can use "lgtv {host} {command} ssl"

Yes finally that did it, thanks burnee!