venkat-srinivasan-nexusflow commited on
Commit
0f867ca
β€’
1 Parent(s): ab37a24

Update tools.py

Browse files

Handle HTTP failures more robustly.

Files changed (1) hide show
  1. tools.py +13 -9
tools.py CHANGED
@@ -61,15 +61,19 @@ class Tools:
61
  "country": "United States",
62
  "region": "CA",
63
  }
64
- response = requests.get(
65
- f"https://pro.ip-api.com/json/{self.client_ip}?key={self.config.ip_api_key}"
66
- )
67
- if not response.ok:
68
- print(f"Not able to find user. Defaulting to {default_response}")
69
- return default_response
70
-
71
- response = response.json()
72
- if response["status"] != "success":
 
 
 
 
73
  print(f"Not able to find user. Defaulting to {default_response}")
74
  return default_response
75
 
 
61
  "country": "United States",
62
  "region": "CA",
63
  }
64
+ try:
65
+ response = requests.get(
66
+ f"https://pro.ip-api.com/json/{self.client_ip}?key={self.config.ip_api_key}"
67
+ )
68
+ if not response.ok:
69
+ print(f"Not able to find user. Defaulting to {default_response}")
70
+ return default_response
71
+
72
+ response = response.json()
73
+ if response["status"] != "success":
74
+ print(f"Not able to find user. Defaulting to {default_response}")
75
+ return default_response
76
+ except:
77
  print(f"Not able to find user. Defaulting to {default_response}")
78
  return default_response
79