Comment 11 for bug 1559072

Revision history for this message
Matt Riedemann (mriedem) wrote : Re: exceptions.from_response with webob 1.6.0 results in "AttributeError: 'unicode' object has no attribute 'get'"

Here is what a 404 response looks like with novaclient and webob 1.5.1:

DEBUG (session:248) REQ: curl -g -i -X GET http://9.5.126.108:8774/v2.1/e4f68bae118f46fa986e3fd54cbacb1e/flavors/test -H "User-Agent: python-novaclient" -H "Accept: application/json" -H "X-OpenStack-Nova-API-Version: 2.25" -H "X-Auth-Token: {SHA1}8b87e089d79ad483b178bdf673e9639ffd86d529"
DEBUG (connectionpool:387) "GET /v2.1/e4f68bae118f46fa986e3fd54cbacb1e/flavors/test HTTP/1.1" 404 77
DEBUG (session:277) RESP: [404] Content-Length: 77 X-Compute-Request-Id: req-d9df03b0-4150-4b53-8157-7560ccf39f75 Vary: X-OpenStack-Nova-API-Version Connection: keep-alive X-Openstack-Nova-Api-Version: 2.25 Date: Fri, 18 Mar 2016 22:30:46 GMT Content-Type: application/json; charset=UTF-8
RESP BODY: {"itemNotFound": {"message": "Flavor test could not be found.", "code": 404}}

So the body is a dict of dicts, where I guess the error message keys to the body, which is how the code expected it to work in novaclient.

>>> body = {"itemNotFound": {"message": "Flavor test could not be found.", "code
": 404}}
>>> body[list(body)[0]]
{'message': 'Flavor test could not be found.', 'code': 404}
>>>

But now we get something like:

{"message": "The resource could not be found.<br /><br />\n\n\n", "code": "404 Not Found", "title": "Not Found"}

Note that even with webob 1.5.1 the content-type in the response is application/json, so it doesn't really help us to key off that to handle this. We basically can't trust the format until we require at least webob>=1.6.0.