Ad

Python Socket.io Client Fails On Event With Dictionary And List Message

I have python-socketio==4.3.1 installed, and I can connect to the socket.io server correctly.

Whenever I receive a message though, I get an exception. The data I would get would be a list on the connect event, and a dictionary on message events.

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.7/site-packages/socketio/client.py", line 581, in _handle_eio_message
    self._handle_event(pkt.namespace, pkt.id, pkt.data)
  File "/usr/local/lib/python3.7/site-packages/socketio/client.py", line 470, in _handle_event
    r = self._trigger_event(data[0], namespace, *data[1:])
  File "/usr/local/lib/python3.7/site-packages/socketio/client.py", line 514, in _trigger_event
    if namespace in self.handlers and event in self.handlers[namespace]:
TypeError: unhashable type: 'list'

Exception in thread Thread-6:
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.7/site-packages/socketio/client.py", line 581, in _handle_eio_message
    self._handle_event(pkt.namespace, pkt.id, pkt.data)
  File "/usr/local/lib/python3.7/site-packages/socketio/client.py", line 470, in _handle_event
    r = self._trigger_event(data[0], namespace, *data[1:])
  File "/usr/local/lib/python3.7/site-packages/socketio/client.py", line 514, in _trigger_event
    if namespace in self.handlers and event in self.handlers[namespace]:
TypeError: unhashable type: 'dict'

I am able to log the messages correctly with a node client. Any ideas?

Code is just this right now:

import socketio
io = socketio.Client()

@io.event
def connect():
    print('connected')

@io.event
def message(data):
    print(data)

url = '...'
io.connect(url)
Ad

Answer

Turns out the error was in the server implementation.

Ad
source: stackoverflow.com
Ad