-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
I've a simple script like this running on my macOS laptop, against a TrueNAS SCALE 24.10 destination.
from truenas_api_client import Client
with Client(uri="ws://FQDN/websocket") as c:
c.call("auth.login_with_api_key", key)
dat = c.call("system.info")
Issue 1
Running this script gives:
(venv) ivanl@ilmac1513 truenas % ./test.py
Websocket client error: ValueError('scheme https is invalid')
Traceback (most recent call last):
File "/Users/ivanl/Documents/src/truenas/./test.py", line 16, in <module>
with Client(uri="ws://FQDN/websocket") as c:
~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ivanl/Documents/src/truenas/venv.nosync/lib/python3.13/site-packages/truenas_api_client/__init__.py", line 93, in __init__
self.__client = client_class(uri, reserved_ports, py_exceptions, log_py_exceptions, call_timeout, verify_ssl)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ivanl/Documents/src/truenas/venv.nosync/lib/python3.13/site-packages/truenas_api_client/legacy.py", line 230, in __init__
raise ClientException(self._connection_error)
truenas_api_client.exc.ClientException: WebSocket connection closed with code=None, reason=None
This is traced to the "Web Interface HTTP -> HTTPS Redirect" setting in TrueNAS UI. By default, this is enabled which causes ws: to be redirected to https which confuses middleware at port 6000.
Issue 2
Once the setting "Web Interface HTTP -> HTTPS Redirect" is disabled, the error msg changes to:
(venv) ivanl@ilmac1513 truenas % ./test.py
Websocket client error: AttributeError("module 'socket' has no attribute 'TCP_KEEPIDLE'")
Traceback (most recent call last):
File "/Users/ivanl/Documents/src/truenas/./test.py", line 16, in <module>
with Client(uri="ws://FQDN/websocket") as c:
~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ivanl/Documents/src/truenas/venv.nosync/lib/python3.13/site-packages/truenas_api_client/__init__.py", line 93, in __init__
self.__client = client_class(uri, reserved_ports, py_exceptions, log_py_exceptions, call_timeout, verify_ssl)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ivanl/Documents/src/truenas/venv.nosync/lib/python3.13/site-packages/truenas_api_client/legacy.py", line 225, in __init__
self._ws.connect()
~~~~~~~~~~~~~~~~^^
File "/Users/ivanl/Documents/src/truenas/venv.nosync/lib/python3.13/site-packages/truenas_api_client/legacy.py", line 60, in connect
self.socket = connect(self.url, sockopt, proxy_info(), None)[0]
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ivanl/Documents/src/truenas/venv.nosync/lib/python3.13/site-packages/websocket/_http.py", line 145, in connect
sock = _open_socket(addrinfo_list, options.sockopt, options.timeout)
File "/Users/ivanl/Documents/src/truenas/venv.nosync/lib/python3.13/site-packages/websocket/_http.py", line 222, in _open_socket
raise error
File "/Users/ivanl/Documents/src/truenas/venv.nosync/lib/python3.13/site-packages/websocket/_http.py", line 209, in _open_socket
sock.connect(address)
~~~~~~~~~~~~^^^^^^^^^
TimeoutError: timed out
macOS do not use TCP_KEEPIDLE like in Linux; instead it uses TCP_KEEPALIVE. Hence it works if line 119 in truenas_api_client/legacy.py is changed from
self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 1)
self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPALIVE, 1)
Metadata
Metadata
Assignees
Labels
No labels