[Kimchi-devel] [PATCH] bug fix: Make URI parameter is not None before encoding it

Aline Manera alinefm at linux.vnet.ibm.com
Tue Feb 25 17:20:17 UTC 2014


From: Aline Manera <alinefm at br.ibm.com>

The following error is raised when the user tried to reboot the host
system:

Request Headers:
  AUTHORIZATION: Basic YWxpbmVmbTowaG5lKjI4ZGljSA==
  Content-Length: 2
  HOST: localhost:8000
  Remote-Addr: 127.0.0.1
  ACCEPT: application/json
  USER-AGENT: curl/7.27.0
  Content-Type: application/json
[25/Feb/2014:14:05:28] HTTP Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/cherrypy/_cprequest.py", line 656, in respond
    response.body = self.handler()
  File "/usr/lib/python2.7/dist-packages/cherrypy/lib/encoding.py", line 188, in __call__
    self.body = self.oldhandler(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/cherrypy/_cpdispatch.py", line 34, in __call__
    return self.callable(*self.args, **self.kwargs)
  File "/home/alinefm/kimchi/src/kimchi/control/base.py", line 79, in wrapper
    for arg in self.model_args])
AttributeError: 'NoneType' object has no attribute 'encode'

It is because /host resource has no parameter and fails to encode() the
None value.
So fix it by verifying the parameter is not None in order to make the
encode() call.

Signed-off-by: Aline Manera <alinefm at br.ibm.com>
---
 src/kimchi/control/base.py |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/kimchi/control/base.py b/src/kimchi/control/base.py
index 91a70ae..5d1f380 100644
--- a/src/kimchi/control/base.py
+++ b/src/kimchi/control/base.py
@@ -75,9 +75,13 @@ class Resource(object):
                 fn = getattr(self.model, model_fn(self, action_name))
                 ident = fn(*model_args)
                 self._redirect(ident)
-                uri_params = tuple([urllib2.quote(arg.encode('utf-8'), safe="")
-                                    for arg in self.model_args])
-                raise internal_redirect(self.uri_fmt % uri_params)
+                uri_params = []
+                for arg in self.model_args:
+                    if arg is None:
+                        arg = ''
+                    uri_params.append(urllib2.quote(arg.encode('utf-8'),
+                                      safe=""))
+                raise internal_redirect(self.uri_fmt % tuple(uri_params))
             except MissingParameter, e:
                 raise cherrypy.HTTPError(400, e.message)
             except InvalidParameter, e:
-- 
1.7.10.4




More information about the Kimchi-devel mailing list