Valentin Valentin - 4 years ago 100
Python Question

API Rest Python

I'm working with

Python API Rest
. I want to display list of directories inside one directory which have this parent ID : 8552450

I'm using this documentation :

So I have this command :

url = ''
payload = {'folderId': 8552450}

headers = {'Accept': 'application/json'}
r = requests.get(url, params=payload, headers=headers, auth=('***', '***'))

rbody = r.content
print rbody

And I get :

[{"id":8978437,"name":"LKJLKJ_OKJKJ_1900-09-12","parentId":8552450,"description":"","lastModified":"2017-02-06 14:45:40 +0100","type":0,"templateId":null,"templateLocked":0,"creation":"2017-02-06 14:45:40 +0100","creator":"Etat Civil","position":1,"hidden":0,"foldRef":null,"attributes":[],"storage":null,"tags":[]}]

Then, I just want to get
result :


So I tried 2 things :

print rbody["name"]
print rbody[1]

But it doesn't work. Have you an idea about command I've to write ?

Thank you

Answer Source

Given your rbody result it would be


However if rbody is a string, you need to first turn it into a Python object

>>> import json
>>> s = '''[{"id":8978437,"name":"LKJLKJ_OKJKJ_1900-09-12","parentId":8552450,"description":"","lastModified":"2017-02-06 14:45:40 +0100","type":0,"templateId":null,"templateLocked":0,"creation":"2017-02-06 14:45:40 +0100","creator":"Etat Civil","position":1,"hidden":0,"foldRef":null,"attributes":[],"storage":null,"tags":[]}]'''
>>> json.loads(s)[0]['name']
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download