On 02/26/2014 04:44 AM, Shu Ming wrote:
δΊ 2014/2/26 1:20, Aline Manera ει:
> From: Aline Manera <alinefm(a)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(a)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=""))
You can change the lines above into:
for arg in self.model_args:
if arg is not None:
uri_params.append(urllib2.quote(arg.encode('utf-8'),
safe=""))
ok
> + raise internal_redirect(self.uri_fmt %
> tuple(uri_params))
> except MissingParameter, e:
> raise cherrypy.HTTPError(400, e.message)
> except InvalidParameter, e: