WebSocket-for-Python
WebSocket-for-Python copied to clipboard
Exception in ssl wrapper when used in Kodi - possible fix
Hi! I have used the ws4py in Kodi and works great without SSL.
But it crash with SSL, like this:
File "C:\Kodi\addons\script.motr\resources\lib\ws4py\client\__init__.py", line 214, in connect self.sock = ssl.wrap_socket(self.sock, **self.ssl_options) File "C:\Kodi\system\python\Lib\ssl.py", line 943, in wrap_socket ciphers=ciphers) File "C:\Kodi\system\python\Lib\ssl.py", line 590, in __init__ self.getpeername() File "C:\Kodi\system\python\Lib\socket.py", line 228, in meth return getattr(self._sock,name)(*args) error: [Errno 10057] En foresp�rsel om � sende eller motta data ble forkastet fordi socketen ikke er tilkoblet og (ved sending p� en datagramsocket som bruker et sendto-kall) ingen adresse var angitt -->End of Python script error report<--
After checking the error, I changed the ws4py\client_init_.py line 207 in connect()
As found:
def connect(self):
"""
Connects this websocket and starts the upgrade handshake
with the remote endpoint.
"""
if self.scheme == "wss":
# default port is now 443; upgrade self.sender to send ssl
self.sock = ssl.wrap_socket(self.sock, **self.ssl_options)
self._is_secure = True
**self.sock.connect(self.bind_addr)**
self._write(self.handshake_request)
(...)
As left:
def connect(self):
"""
Connects this websocket and starts the upgrade handshake
with the remote endpoint.
"""
#FIX? To make the WSS work, connect and then warp: 13.02.18 Lars Werner
**self.sock.connect(self.bind_addr)**
if self.scheme == "wss":
# default port is now 443; upgrade self.sender to send ssl
self.sock = ssl.wrap_socket(self.sock, **self.ssl_options)
self._is_secure = True
self._write(self.handshake_request)
(...)
I'm not a great Python coder (just used it for a couple of weeks) but it seems to work perfectly by doing so. And it upgrades the socket to SSL as it should.
Any comments on this easy "fix"?