Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError from websocket.py #292

Open
sslupsky opened this issue Nov 2, 2024 · 6 comments
Open

TypeError from websocket.py #292

sslupsky opened this issue Nov 2, 2024 · 6 comments

Comments

@sslupsky
Copy link

sslupsky commented Nov 2, 2024

Recent commit appears to be causing a TypeError: cb60792

Here is the error:

Exception in thread WebSocketClient:
Traceback (most recent call last):
  File "/Users/stevenslupsky/.local/share/mise/installs/python/3.8.18/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/Users/stevenslupsky/.local/share/mise/installs/python/3.8.18/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/stevenslupsky/.local/share/mise/installs/python/3.8.18/lib/python3.8/site-packages/ws4py/websocket.py", line 528, in run
    if not self.once():
  File "/Users/stevenslupsky/.local/share/mise/installs/python/3.8.18/lib/python3.8/site-packages/ws4py/websocket.py", line 410, in once
    if not self.process(self.buf[:requested]):
  File "/Users/stevenslupsky/.local/share/mise/installs/python/3.8.18/lib/python3.8/site-packages/ws4py/websocket.py", line 465, in process
    logger.debug("Closing message received (%d): %s" % (s.closing.code, s.closing.reason.decode() if isinstance(s.closing.reason, bytes) else s.closing.reason))
TypeError: isinstance() arg 2 must be a type or tuple of types

See also: klattimer/LGWebOSRemote#172

Seems like the error might be from this line:

if not self.process(self.buf[:requested]):

The second parameter is null.

@sslupsky sslupsky changed the title Wrong type TypeError from websocket.py Nov 2, 2024
@auvipy
Copy link
Collaborator

auvipy commented Nov 3, 2024

thanks, i got them in the CI as well
test_parse_unix_schemes (test.test_client.BasicClientTest) ... /home/runner/work/WebSocket-for-Python/WebSocket-for-Python/test/test_client.py:37: ResourceWarning: unclosed <socket.socket fd=3, family=AddressFamily.AF_UNIX, type=SocketKind.SOCK_STREAM, proto=0>
c = WebSocketBaseClient(url="wss+unix:///my.socket")
/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/unittest/case.py:605: ResourceWarning: unclosed <socket.socket fd=4, family=AddressFamily.AF_UNIX, type=SocketKind.SOCK_STREAM, proto=0>
testMethod()
ok
test_parse_ws_scheme (test.test_client.BasicClientTest) ... /opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/unittest/case.py:605: ResourceWarning: unclosed <socket.socket fd=3, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('0.0.0.0', 0)>
testMethod()
ok
test_parse_ws_scheme_when_missing_resource (test.test_client.BasicClientTest) ... ok
test_parse_ws_scheme_with_port (test.test_client.BasicClientTest) ... ok
test_parse_ws_scheme_with_query_string (test.test_client.BasicClientTest) ... ok
test_parse_wss_scheme (test.test_client.BasicClientTest) ... ok
test_parse_wss_scheme_when_missing_resource (test.test_client.BasicClientTest) ... ok
test_parse_wss_scheme_with_port (test.test_client.BasicClientTest) ... ok
test_parse_wss_scheme_with_query_string (test.test_client.BasicClientTest) ... ok
test_thread_is_started_once_connected (test.test_client.ThreadedClientTest) ... Exception in thread WebSocketClient:
Traceback (most recent call last):
File "/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/home/runner/work/WebSocket-for-Python/WebSocket-for-Python/ws4py/websocket.py", line 528, in run
if not self.once():
File "/home/runner/work/WebSocket-for-Python/WebSocket-for-Python/ws4py/websocket.py", line 410, in once
if not self.process(self.buf[:requested]):
File "/home/runner/work/WebSocket-for-Python/WebSocket-for-Python/ws4py/websocket.py", line 465, in process
logger.debug("Closing message received (%d): %s" % (s.closing.code, s.closing.reason.decode() if isinstance(s.closing.reason, bytes) else s.closing.reason))
TypeError: isinstance() arg 2 must be a type or tuple of types

ok
test_thread_is_started_once_connected_secure (test.test_client.ThreadedClientTest)
Same as the above test, but with SSL socket ... Exception in thread WebSocketClient:
Traceback (most recent call last):
File "/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/home/runner/work/WebSocket-for-Python/WebSocket-for-Python/ws4py/websocket.py", line 528, in run
if not self.once():
File "/home/runner/work/WebSocket-for-Python/WebSocket-for-Python/ws4py/websocket.py", line 410, in once
if not self.process(self.buf[:requested]):
File "/home/runner/work/WebSocket-for-Python/WebSocket-for-Python/ws4py/websocket.py", line 465, in process
logger.debug("Closing message received (%d): %s" % (s.closing.code, s.closing.reason.decode() if isinstance(s.closing.reason, bytes) else s.closing.reason))
TypeError: isinstance() arg 2 must be a type or tuple of types

@jolaf
Copy link
Contributor

jolaf commented Nov 3, 2024

I wonder why bytes is not recognized as a type.

Maybe it's overridden by some local variable?

@jolaf
Copy link
Contributor

jolaf commented Nov 3, 2024

The second parameter is null.

This should not cause any problems by itself.

@sslupsky
Copy link
Author

sslupsky commented Nov 3, 2024

I think the problem is that when process() is called at line 410, it makes the call without including the second parameter, namely bytes and the definition of process() does not define the default argument. So, there is no "bytes" object (it is None).

@jolaf
Copy link
Contributor

jolaf commented Nov 3, 2024

The problem is process() second argument is named bytes, which is Python name for built-in type.
Of course, isinstance(anything, bytes) would fail in this situation, because bytes is not a type.

To fix this problem, the process() argument should be renamed to something more reasonable, like data.

@jolaf
Copy link
Contributor

jolaf commented Nov 12, 2024

It looks like this issue is fixed and can be closed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants