django-socketio icon indicating copy to clipboard operation
django-socketio copied to clipboard

example_project russian words.

Open MechanisM opened this issue 14 years ago • 15 comments

example_project russian words sended but doesn't appears.

MechanisM avatar Aug 13 '11 12:08 MechanisM

I just tested some Russian characters and it works fine - you'll have to be more specific.

stephenmcd avatar Aug 13 '11 13:08 stephenmcd

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

MechanisM avatar Aug 13 '11 13:08 MechanisM

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

stephenmcd avatar Aug 13 '11 13:08 stephenmcd

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?

symphonical avatar Feb 22 '12 15:02 symphonical

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.

Madd avatar Feb 22 '12 16:02 Madd

Might be worth posting an issue and pull request on https://bitbucket.org/Jeffrey/gevent-socketio/

stephenmcd avatar Feb 22 '12 20:02 stephenmcd

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 avatar Mar 01 '12 18:03 Madd

@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.

vkolev avatar Mar 17 '12 09:03 vkolev

@Madd works great with Cyrillic letters. Thank you.

petro-rudenko avatar Mar 20 '12 11:03 petro-rudenko

@Madd Works with Polish letters too, thank you.

zlorf avatar Oct 07 '12 19:10 zlorf

Works great. Thank you. Will django_socketio be patched with this fix?

Marcolac avatar Nov 27 '12 21:11 Marcolac

Next steps will include an entirely new version of socket.io which hopefully resolves the issue.

stephenmcd avatar Nov 27 '12 21:11 stephenmcd

Great, that's good news! Any idea on when the new version of socket.io will be released?

Marcolac avatar Nov 27 '12 21:11 Marcolac

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.

stephenmcd avatar Nov 27 '12 21:11 stephenmcd

Madd's solution dont work... How fix this issue?

axce1 avatar Aug 30 '13 01:08 axce1