Spaces:
Runtime error
Runtime error
venkat-srinivasan-nexusflow
commited on
Commit
β’
0f867ca
1
Parent(s):
ab37a24
Update tools.py
Browse filesHandle HTTP failures more robustly.
tools.py
CHANGED
@@ -61,15 +61,19 @@ class Tools:
|
|
61 |
"country": "United States",
|
62 |
"region": "CA",
|
63 |
}
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
|
|
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 |
|