I'm trapping an error but cannot extract what I want out of the returned message. Here's the code:
except purestorage.PureHTTPError as response:
print "LUN Creation failed:"
print dir(response)
print "args:{}".format(response.args)
print "code:{}".format(response.code)
print "headers:{}".format(response.headers)
print "message:{}".format(response.message)
print "reason:{}".format(response.reason)
print "rest_version:{}".format(response.rest_version)
print "target:{}".format(response.target )
print "text:{}".format(response.text)
Here's the output:
LUN Creation failed:
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__getslice__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__unicode__', '__weakref__', 'args', 'code', 'headers', 'message', 'reason', 'rest_version', 'target', 'text']
args:()
code:400
headers:{'Content-Length': '113', 'Set-Cookie': 'session=....; Expires=Wed, 05-Jul-2017 16:28:26 GMT; HttpOnly; Path=/', 'Server': 'nginx/1.4.6 (Ubuntu)', 'Connection': 'keep-alive', 'Date': 'Wed, 05 Jul 2017 15:58:26 GMT', 'Content-Type': 'application/json'}
message:
reason:BAD REQUEST
rest_version:1.8
target:array1
text:[{"pure_err_key": "err.friendly", "code": 0, "ctx": "lun-name", "pure_err_code": 1, "msg": "Volume already exists."}]
I want to pull out msg and pure_err_code but the text isn't a list.
The [{ ... }] is confusing me. The response.text[0] is [ and response.text['msg'] throws an index error so this is acting like a string (afaIk).