django-socketio
                                
                                 django-socketio copied to clipboard
                                
                                    django-socketio copied to clipboard
                            
                            
                            
                        example_project russian words.
example_project russian words sended but doesn't appears.
I just tested some Russian characters and it works fine - you'll have to be more specific.
Traceback (most recent call last): File "/usr/lib/pymodules/python2.7/gevent/greenlet.py", line 405, in run result = self._run(_self.args, *_self.kwargs) File "/home/mechanism/ENV/local/lib/python2.7/site-packages/socketio/server.py", line 49, in handle handler.handle() File "/usr/lib/pymodules/python2.7/gevent/pywsgi.py", line 167, in handle result = self.handle_one_request() File "/usr/lib/pymodules/python2.7/gevent/pywsgi.py", line 288, in handle_one_request self.handle_one_response() File "/home/mechanism/ENV/local/lib/python2.7/site-packages/socketio/handler.py", line 68, in handle_one_response jobs = self.transport.connect(session, request_method) File "/home/mechanism/ENV/local/lib/python2.7/site-packages/socketio/transports.py", line 101, in connect return self.handle_post_response(session) File "/home/mechanism/ENV/local/lib/python2.7/site-packages/socketio/transports.py", line 67, in handle_post_response messages = self.decode(data) File "/home/mechanism/ENV/local/lib/python2.7/site-packages/socketio/transports.py", line 16, in decode return self.handler.environ['socketio'].decode(data) File "/home/mechanism/ENV/local/lib/python2.7/site-packages/socketio/protocol.py", line 113, in decode messages.append(json.loads(data[3:size])) File "/usr/lib/python2.7/dist-packages/simplejson/init.py", line 385, in loads return _default_decoder.decode(s) File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 402, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 418, in raw_decode obj, end = self.scan_once(s, idx) JSONDecodeError: Unterminated string starting at: line 1 column 39 (char 39) <Greenlet at 0x3dd85a0: <bound method SocketIOServer.handle of <SocketIOServer at 0x33ead10 fileno=4 address=127.0.0.1:8084>>(<socket at 0x3ddec90 fileno=37 sock=127.0.0.1:, ('127.0.0.1', 58103))> failed with JSONDecodeError
this is output after sending russian words in chat
Looks like a problem in gevent-socketio so you might want to raise an issue with that project.
I've got a temp room set up here where it's working with Russian characters fine:
http://122.248.211.213:9000/test
Got almost the same error as MechanisM.
// javascript socket.send({test:'æ'}); // æ=norwegian letter, sent as utf8 from client.
// server console .raceback (most recent call last): File "/home/terjeto/.virtualenvs/harmony/local/lib/python2.7/site-packages/gevent/greenlet.py", line 390, in run result = self._run(_self.args, *_self.kwargs) File "/home/terjeto/.virtualenvs/harmony/local/lib/python2.7/site-packages/socketio/server.py", line 49, in handle handler.handle() File "/home/terjeto/.virtualenvs/harmony/local/lib/python2.7/site-packages/gevent/pywsgi.py", line 180, in handle result = self.handle_one_request() File "/home/terjeto/.virtualenvs/harmony/local/lib/python2.7/site-packages/gevent/pywsgi.py", line 314, in handle_one_request self.handle_one_response() File "/home/terjeto/.virtualenvs/harmony/local/lib/python2.7/site-packages/socketio/handler.py", line 68, in handle_one_response jobs = self.transport.connect(session, request_method) File "/home/terjeto/.virtualenvs/harmony/local/lib/python2.7/site-packages/socketio/transports.py", line 155, in connect return self.handle_post_response(session) File "/home/terjeto/.virtualenvs/harmony/local/lib/python2.7/site-packages/socketio/transports.py", line 67, in handle_post_response messages = self.decode(data) File "/home/terjeto/.virtualenvs/harmony/local/lib/python2.7/site-packages/socketio/transports.py", line 16, in decode return self.handler.environ['socketio'].decode(data) File "/home/terjeto/.virtualenvs/harmony/local/lib/python2.7/site-packages/socketio/protocol.py", line 113, in decode messages.append(json.loads(data[3:size])) File "/home/terjeto/.virtualenvs/harmony/local/lib/python2.7/site-packages/simplejson/init.py", line 384, in loads return _default_decoder.decode(s) File "/home/terjeto/.virtualenvs/harmony/local/lib/python2.7/site-packages/simplejson/decoder.py", line 402, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/home/terjeto/.virtualenvs/harmony/local/lib/python2.7/site-packages/simplejson/decoder.py", line 418, in raw_decode obj, end = self.scan_once(s, idx) JSONDecodeError: Expecting object: line 1 column 11 (char 11) <Greenlet at 0x90f448c: <bound method SocketIOServer.handle of <SocketIOServer at 0x8bd1fcc fileno=4 address=0.0.0.0:7000>>(<socket at 0x908504c fileno=[Errno 9] Bad file des, ('192.168.0.196', 49944))> failed with JSONDecodeError
Any ideas how to solve?
The size variable is not correct in socketio/protocol.py:
_, size, data = data.split(MSG_FRAME, 2)
Because this will make the string longer than whats recieved as argument "data":
data = urllib.unquote_plus(data)
I have done fixed this by doing:
    if frame_type == JSON_FRAME:
        size = len(data)
        messages.append(json.loads(data[3:]))
Don't know if this is a good solution, but it seems to be working.
Might be worth posting an issue and pull request on https://bitbucket.org/Jeffrey/gevent-socketio/
Okey, I found where the problem is really located.. It's in the socket.io.js on line 140 where the message length is generated. The javascript does not count the message as escaped which the back-end does. This will make the json break at simplejson.loads().
https://github.com/stephenmcd/django-socketio/blob/master/django_socketio/static/js/socket.io.js#L140
Change the line in the js file from:
ret += frame + message.length + frame + message;
to:
ret += frame + unescape(encodeURIComponent(message)).length + frame + message;
@Madd I can confirm that your solution is working with Cyrillic letters. Thanks for the add :) I hope that django-socketio will be patched in the future with this fix.
@Madd works great with Cyrillic letters. Thank you.
@Madd Works with Polish letters too, thank you.
Works great. Thank you. Will django_socketio be patched with this fix?
Next steps will include an entirely new version of socket.io which hopefully resolves the issue.
Great, that's good news! Any idea on when the new version of socket.io will be released?
I can't give a time frame other than "as soon as possible", in as much as I absolutely intend for it to happen when I have time available.
Madd's solution dont work... How fix this issue?