Fix NoneType crash: API returns null result instead of missing key

dict.get("result", []) returns None when key exists with null value.
Changed to resp.get("result") or [] which handles both cases.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
David Kiania 2026-04-08 17:27:48 +03:00
parent 326764e1a0
commit e1402f6af1
2 changed files with 6 additions and 6 deletions

View file

@ -57,7 +57,7 @@ def poll_alarms():
"page_size": 100
}, token)
alarms = resp.get("result", [])
alarms = resp.get("result") or []
if not alarms: continue
with get_conn() as conn:

View file

@ -50,7 +50,7 @@ def sync_devices():
resp = api_post("jimi.user.device.list", {"target": TARGET_ACCOUNT}, token)
if resp.get("code") != 0: return
devices = resp.get("result", [])
devices = resp.get("result") or []
upserted = 0
with get_conn() as conn:
@ -60,7 +60,7 @@ def sync_devices():
if not imei: continue
detail_resp = api_post("jimi.track.device.detail", {"imei": imei}, token)
dtl = detail_resp.get("result", {}) if detail_resp.get("code") == 0 else {}
dtl = detail_resp.get("result") or {} if detail_resp.get("code") == 0 else {}
cur.execute("""
INSERT INTO tracksolid.devices (
@ -106,7 +106,7 @@ def poll_live_positions():
resp = api_post("jimi.user.device.location.list", {"target": TARGET_ACCOUNT, "map_type": "GOOGLE"}, token)
if resp.get("code") != 0: return
positions = resp.get("result", [])
positions = resp.get("result") or []
upserted, inserted = 0, 0
with get_conn() as conn:
@ -170,7 +170,7 @@ def poll_trips():
"end_time": end_ts.strftime("%Y-%m-%d %H:%M:%S")
}, token)
trips = resp.get("result", [])
trips = resp.get("result") or []
with get_conn() as conn:
with conn.cursor() as cur:
for t in trips:
@ -214,7 +214,7 @@ def poll_parking():
"end_time": end_ts.strftime("%Y-%m-%d %H:%M:%S"),
}, token)
events = resp.get("result", [])
events = resp.get("result") or []
with get_conn() as conn:
with conn.cursor() as cur:
for p in events: