Может ли кто-нибудь помочь мне получить доступ к полю "нумерация страниц" в следующем ответе API?Я пробовал код ниже, но получаю сообщение об ошибке «нумерация страниц».Это работает для «заголовка», поэтому я не уверен, что отличается.Полная ошибка ниже.
Traceback (most recent call last):
File "myscript.py", line 172, in <module>
pag_object = (data['pagination'])
KeyError: 'pagination'
Мой код:
response = requests.get("https://api.weather.gov/alerts?limit=1", timeout=5)
data = response.json()
pag_object = (data['pagination'])
Я подтвердил, что JSON действителен.Фрагмент ниже.
{
"@context": [
"https://raw.githubusercontent.com/geojson/geojson-ld/master/contexts/geojson-base.jsonld",
{
"wx": "https://api.weather.gov/ontology#",
"@vocab": "https://api.weather.gov/ontology#"
}
],
"type": "FeatureCollection",
"features": [{
"id": "http://api.weather.gov/alerts/NWS-IDP-PROD-KEEPALIVE-22613",
"type": "Feature",
"properties": {
"@type": "wx:Alert",
"id": "NWS-IDP-PROD-KEEPALIVE-22613",
"areaDesc": "Montgomery",
"geocode": {
"UGC": [
"MDC031"
],
"SAME": [
"024031"
]
},
"affectedZones": [
"http://api.weather.gov/zones/county/MDC031"
],
"references": [],
"sent": "2018-05-21T14:05:51+00:00",
"event": "Test Message",
"senderName": "NWS",
"description": "Monitoring message only. Please disregard.",
"parameters": {
"PIL": [
"NWSKEPWBC"
],
"BLOCKCHANNEL": [
"CMAS",
"NWEM"
]
}
}
}],
"title": "Watches, warnings, and advisories",
"pagination": {
"next": "http://api.weather.gov/alerts?limit=1&cursor=eyJ0IjoxNTI2OTExNTUxLCJpIjoiTldTLUlEUC1QUk9ELUtFRVBBTElWRS0yMjYxMyJ9"
}
}