MrJoes/tornadio2 — Issue #7: on_event fails with unicode dict keys
Author: beardygeek
Created: 2011-11-14 22:58:08+00:00
State: open

I was overriding on_event, and sending keyword arguments from the client:

```javascript
socket.emit('channel1', {msg: 'hello'});
```

I kept getting the error:

File "/ws_env/src/tornadio2/tornadio2/session.py", line 386, in raw_message
conn.on_event(event['name'], **args[0])
TypeError: on_event() keywords must be strings

I'm using Chrome, and after putting a print statement in the Tornadio source, it seems that somewhere along the line, (possibly in the Socket.io library, although I'm not entirely sure) both the key and value are being converted to unicode strings, which can't be accepted as kwargs.

I patched the source to create a new dict, and convert all the keys and values into plain strings, and this seems to have fixed the issue (around line 384 in session.py):

```python
if len(args) == 1 and isinstance(args[0], dict):
str_args = {}
for k, v in args[0].iteritems():
str_args[str(k)] = str(v)
conn.on_event(event['name'], **str_args)
else:
conn.on_event(event['name'], *args)
```

Perhaps there's a more elegant way of solving this, and it might also affect other parts of the raw message handling.

Thanks

Stuart