[Kimchi-devel] [PATCH] bug fix: Make URI parameter is not None before encoding it
Aline Manera
alinefm at linux.vnet.ibm.com
Wed Feb 26 18:28:05 UTC 2014
On 02/26/2014 03:23 PM, Aline Manera wrote:
> On 02/26/2014 04:44 AM, Shu Ming wrote:
>> 于 2014/2/26 1:20, Aline Manera 写道:
>>> 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=""))
>>
>> 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
>
In fact, it is not possible.
The internal_redirect needs all the args. So we can consider "".
When I tried it I got:
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
[26/Feb/2014:15:25:09] 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 78, in
wrapper
raise internal_redirect(self.uri_fmt % tuple(uri_params))
TypeError: not enough arguments for format string
TypeError: not enough arguments for format string
>>
>>
>>
>>> + raise internal_redirect(self.uri_fmt %
>>> tuple(uri_params))
>>> except MissingParameter, e:
>>> raise cherrypy.HTTPError(400, e.message)
>>> except InvalidParameter, e:
>>
>
> _______________________________________________
> Kimchi-devel mailing list
> Kimchi-devel at ovirt.org
> http://lists.ovirt.org/mailman/listinfo/kimchi-devel
More information about the Kimchi-devel
mailing list