dcorking / wave-robot-python-client

Automatically exported from code.google.com/p/wave-robot-python-client
Apache License 2.0
0 stars 0 forks source link

Properly encode incoming json message #12

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.Any robot message with unicode (non-ascii) characters will cause an 
exception in the appengine log. Here is an example:
08-12 11:01PM 49.150
Traceback (most recent call last):
E 08-12 11:01PM 49.150
  File "/base/python_lib/versions/1/google/appengine/api/app_logging.py", 
line 71, in emit
E 08-12 11:01PM 49.150
    self.stream.write(message.encode("UTF-8"))
E 08-12 11:01PM 49.151
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position 371: 
ordinal not in range(128)

What is the expected output? What do you see instead?
No exception should be thrown.

What version of the product are you using? On what operating system? r11 on 
linux (2.6.27-grsec #2 SMP CentOS 4.7)

Please provide any additional information below.
This patch will fix the problem:

diff -r 906f7821fef6 api/robot.py
--- a/api/robot.py      Tue Aug 11 13:48:42 2009 -0700
+++ b/api/robot.py      Wed Aug 12 23:32:23 2009 -0700
@@ -83,7 +83,7 @@
     if not json_body:
       # TODO(davidbyttow): Log error?
       return
-    logging.info('Incoming: ' + json_body)
+    logging.info('Incoming: ' + unicode(json_body,'utf8','replace'))

     context, events = robot_abstract.ParseJSONBody(json_body)
     for event in events:

Original issue reported on code.google.com by chakra...@gmail.com on 13 Aug 2009 at 6:36

GoogleCodeExporter commented 9 years ago
Thanks for the report!

Original comment by pamela.fox on 1 Oct 2009 at 5:16