Read from requests.get
Question:
i have this request but its with a strange behaviour and im having dificulties get the values a need.
heres an example:
response = requests.get('https://api-prd.dev/analytics/api/properties?filter[a.id]=' + aid, headers=headers)
request = response.json()
print(":0:->>>> ", request['data'][0])
the prints are like this:
:0:->>>> {'type': 'id-snapshot-property', 'id': 'adblue_level_percentage', 'attributes': {'updateDate': '2022-10-07T13:39:32Z', 'value': '0'}}
How do i get the value 0 in adblue_level_percentage
response: request['data'][0]['attributes']['value']
Answers:
import json
response = requests.get('https://api-prd.dev/analytics/api/properties?filter[a.id]=' + aid, headers=headers)
request = json.loads(response)
now you have dict object and fetch value by calling dict key
response = requests.get('https://api-prd.dev/analytics/api/properties?filter[a.id]=' + aid, headers=headers)
data = response.json()
This should also work. It also delivers a dictionary which you can access via its keys.
>>> import requests
>>> r = requests.get('https://api.github.com/events')
>>> r.json()
[{'repository': {'open_issues': 0, 'url': 'https://github.com/...'}}]
i have this request but its with a strange behaviour and im having dificulties get the values a need.
heres an example:
response = requests.get('https://api-prd.dev/analytics/api/properties?filter[a.id]=' + aid, headers=headers)
request = response.json()
print(":0:->>>> ", request['data'][0])
the prints are like this:
:0:->>>> {'type': 'id-snapshot-property', 'id': 'adblue_level_percentage', 'attributes': {'updateDate': '2022-10-07T13:39:32Z', 'value': '0'}}
How do i get the value 0 in adblue_level_percentage
response: request['data'][0]['attributes']['value']
import json
response = requests.get('https://api-prd.dev/analytics/api/properties?filter[a.id]=' + aid, headers=headers)
request = json.loads(response)
now you have dict object and fetch value by calling dict key
response = requests.get('https://api-prd.dev/analytics/api/properties?filter[a.id]=' + aid, headers=headers)
data = response.json()
This should also work. It also delivers a dictionary which you can access via its keys.
>>> import requests
>>> r = requests.get('https://api.github.com/events')
>>> r.json()
[{'repository': {'open_issues': 0, 'url': 'https://github.com/...'}}]