fiorix/cyclone — Issue #31: UnicodeEncodeError thrown when sending Encode characters through websocket.
Author: zyyang
Created: 2011-11-17 10:19:48+00:00
State: open

hi,
There is a small problem with the new websocket support.
When I send Chinese characters through websocket, it will raise an exception:

------------------------------------------------------------------------------------------------------------------------
Traceback (most recent call last):
..............(useless logs).........
handler._execute(transforms, *args, **kwargs)
File "/Users/daniel/Sites/nli_env/lib/python2.6/site-packages/cyclone-0.7-py2.6.egg/cyclone/web.py", line 1120, in _execute
self.connectionMade(*args, **kwargs)
File "/Users/daniel/Downloads/Dev/breeze/breeze/views/order.py", line 24, in connectionMade
self.sendMessage("测试")
File "/Users/daniel/Sites/nli_env/lib/python2.6/site-packages/cyclone-0.7-py2.6.egg/cyclone/web.py", line 949, in sendMessage
newFrame += message.encode()
exceptions.UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)

------------------------------------------------------------------------------------------------------------------------

(FYI) It works fine when I change the file web.py, line 949 to:
newFrame += message.encode('utf-8')