[Kimchi-devel] [PATCH] [Wok 3/3] Bug fix: Properly encode unicode string

Aline Manera alinefm at linux.vnet.ibm.com
Wed Mar 2 19:17:34 UTC 2016


The data sends/receives to server is on unicode format.
So we need to encode it to UTF-8 to get the string representation.

This problem was identified when running Kimchi tests in which the
following error was displayed:

[02/Mar/2016:11:51:42] HTTP Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/cherrypy/_cprequest.py", line 670, in respond
    response.body = self.handler()
  File "/usr/lib/python2.7/site-packages/cherrypy/lib/encoding.py", line 217, in __call__
    self.body = self.oldhandler(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/cherrypy/_cpdispatch.py", line 61, in __call__
    return self.callable(*self.args, **self.kwargs)
  File "/home/alinefm/wok/src/wok/control/base.py", line 136, in wrapper
    params = {'ident': str(model_args[0])}
UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-3: ordinal not in range(128)

Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
---
 src/wok/control/base.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/wok/control/base.py b/src/wok/control/base.py
index 3dd3fb8..79dd22c 100644
--- a/src/wok/control/base.py
+++ b/src/wok/control/base.py
@@ -131,7 +131,7 @@ class Resource(object):
 
                 params = {}
                 if model_args:
-                    params = {'ident': str(model_args[0])}
+                    params = {'ident': model_args[0].encode('utf-8')}
 
                 RequestRecord(
                     self.getRequestMessage(method, action_name) % params,
@@ -179,7 +179,7 @@ class Resource(object):
             method = 'DELETE'
             params = {}
             if self.model_args:
-                params = {'ident': str(self.model_args[0])}
+                params = {'ident': self.model_args[0].encode('utf-8')}
 
             RequestRecord(
                 self.getRequestMessage(method, 'default') % params,
-- 
2.5.0




More information about the Kimchi-devel mailing list