From 07ed5a20d108d72328d36094b38735c911c54fee Mon Sep 17 00:00:00 2001 From: Mabrouki Date: Sat, 6 Jun 2026 21:25:08 +0100 Subject: [PATCH] Fix KeyError crash when ipwho.is API omits current_time field - Use .get() with fallback 'N/A' for current_time - Widen exception handlers to catch KeyError alongside ValueError so a single missing API field doesn't crash the entire menu loop --- GhostTR.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GhostTR.py b/GhostTR.py index ccc1455c..5b61f8dc 100644 --- a/GhostTR.py +++ b/GhostTR.py @@ -74,7 +74,7 @@ def IP_Track(): print(f"{Wh} DST :{Gr}", ip_data["timezone"]["is_dst"]) print(f"{Wh} Offset :{Gr}", ip_data["timezone"]["offset"]) print(f"{Wh} UTC :{Gr}", ip_data["timezone"]["utc"]) - print(f"{Wh} Current Time :{Gr}", ip_data["timezone"]["current_time"]) + print(f"{Wh} Current Time :{Gr}", ip_data["timezone"].get("current_time", "N/A")) # ip_data["timezone"]["current_time"] — the ipwho.is API doesn't always include current_time. When it's missing, Python raises KeyError @is_option @@ -232,7 +232,7 @@ def execute_option(opt): call_option(opt) input(f'\n{Wh}[ {Gr}+ {Wh}] {Gr}Press enter to continue') main() - except ValueError as e: + except (ValueError, KeyError) as e: print(e) time.sleep(2) execute_option(opt)