Estoy cogiendo datos de una api en formato json
{
> "images": [
> {
> "OS-EXT-IMG-SIZE:size": 13167616,
> "created": "2021-07-13T09:35:56Z",
> "id": "15f490a5-9b64-4315-a592-3933e91356a5",
> "links": [
> {
> "href": "http://192.168.1.82:8774/v2.1/7d8fed2119e04ee79e15b5a2fac2f5da/images/15f490a5-9b64-4315-a592-3933e91356a5",
> "rel": "self"
> },
> {
> "href": "http://192.168.1.82:8774/7d8fed2119e04ee79e15b5a2fac2f5da/images/15f490a5-9b64-4315-a592-3933e91356a5",
> "rel": "bookmark"
> },
> {
> "href": "http://192.168.1.82:9292/images/15f490a5-9b64-4315-a592-3933e91356a5",
> "rel": "alternate",
> "type": "application/vnd.openstack.image"
> }
> ],
> "metadata": {},
> "minDisk": 0,
> "minRam": 0,
> "name": "cirrios",
> "progress": 100,
> "status": "ACTIVE",
> "updated": "2021-07-13T09:35:57Z"
> },
> {
> "OS-EXT-IMG-SIZE:size": 1020264448,
> "created": "2021-07-11T15:14:03Z",
> "id": "ba417b6f-edde-4862-8425-6d3b1d545dcc",
> "links": [
> {
> "href": "http://192.168.1.82:8774/v2.1/7d8fed2119e04ee79e15b5a2fac2f5da/images/ba417b6f-edde-4862-8425-6d3b1d545dcc",
> "rel": "self"
> },
> {
> "href": "http://192.168.1.82:8774/7d8fed2119e04ee79e15b5a2fac2f5da/images/ba417b6f-edde-4862-8425-6d3b1d545dcc",
> "rel": "bookmark"
> },
> {
> "href": "http://192.168.1.82:9292/images/ba417b6f-edde-4862-8425-6d3b1d545dcc",
> "rel": "alternate",
> "type": "application/vnd.openstack.image"
> }
> ],
> "metadata": {},
> "minDisk": 0,
> "minRam": 0,
> "name": "centos",
> "progress": 100,
> "status": "ACTIVE",
> "updated": "2021-07-11T15:14:22Z"
> }
> ]
> }
>
Los busco así :
try:
result = requests.get(req["images"], headers=headers)
result_data = json.loads(result.content)
except Exception as e :
print('0')
sys.exit("\nError requesting %s, please check conectivity" %(req["images"],))
eso para conectarme y luego con esto pillo lo que me interesa
for dato in result_data["images"] :
value = str(dato['name'])
value = int(dato['progress'])
La cosa es que id, y name me los pilla pero progress, mindisk o minram no, deduzco que es porque no usan comillas?
me da este error :
Traceback (most recent call last): File "openstack3.py", line 263, in value = json.dumps(float(dato['progress'])), KeyError: 'progress'
como tendría que declararlo para coger esos datos??
mindisk
yminram
no se encuentren en todos