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:
parent
326764e1a0
commit
e1402f6af1
2 changed files with 6 additions and 6 deletions
|
|
@ -57,7 +57,7 @@ def poll_alarms():
|
||||||
"page_size": 100
|
"page_size": 100
|
||||||
}, token)
|
}, token)
|
||||||
|
|
||||||
alarms = resp.get("result", [])
|
alarms = resp.get("result") or []
|
||||||
if not alarms: continue
|
if not alarms: continue
|
||||||
|
|
||||||
with get_conn() as conn:
|
with get_conn() as conn:
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ def sync_devices():
|
||||||
resp = api_post("jimi.user.device.list", {"target": TARGET_ACCOUNT}, token)
|
resp = api_post("jimi.user.device.list", {"target": TARGET_ACCOUNT}, token)
|
||||||
if resp.get("code") != 0: return
|
if resp.get("code") != 0: return
|
||||||
|
|
||||||
devices = resp.get("result", [])
|
devices = resp.get("result") or []
|
||||||
upserted = 0
|
upserted = 0
|
||||||
|
|
||||||
with get_conn() as conn:
|
with get_conn() as conn:
|
||||||
|
|
@ -60,7 +60,7 @@ def sync_devices():
|
||||||
if not imei: continue
|
if not imei: continue
|
||||||
|
|
||||||
detail_resp = api_post("jimi.track.device.detail", {"imei": imei}, token)
|
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("""
|
cur.execute("""
|
||||||
INSERT INTO tracksolid.devices (
|
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)
|
resp = api_post("jimi.user.device.location.list", {"target": TARGET_ACCOUNT, "map_type": "GOOGLE"}, token)
|
||||||
if resp.get("code") != 0: return
|
if resp.get("code") != 0: return
|
||||||
|
|
||||||
positions = resp.get("result", [])
|
positions = resp.get("result") or []
|
||||||
upserted, inserted = 0, 0
|
upserted, inserted = 0, 0
|
||||||
|
|
||||||
with get_conn() as conn:
|
with get_conn() as conn:
|
||||||
|
|
@ -170,7 +170,7 @@ def poll_trips():
|
||||||
"end_time": end_ts.strftime("%Y-%m-%d %H:%M:%S")
|
"end_time": end_ts.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
}, token)
|
}, token)
|
||||||
|
|
||||||
trips = resp.get("result", [])
|
trips = resp.get("result") or []
|
||||||
with get_conn() as conn:
|
with get_conn() as conn:
|
||||||
with conn.cursor() as cur:
|
with conn.cursor() as cur:
|
||||||
for t in trips:
|
for t in trips:
|
||||||
|
|
@ -214,7 +214,7 @@ def poll_parking():
|
||||||
"end_time": end_ts.strftime("%Y-%m-%d %H:%M:%S"),
|
"end_time": end_ts.strftime("%Y-%m-%d %H:%M:%S"),
|
||||||
}, token)
|
}, token)
|
||||||
|
|
||||||
events = resp.get("result", [])
|
events = resp.get("result") or []
|
||||||
with get_conn() as conn:
|
with get_conn() as conn:
|
||||||
with conn.cursor() as cur:
|
with conn.cursor() as cur:
|
||||||
for p in events:
|
for p in events:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue