Spaces:
Sleeping
Sleeping
Tuchuanhuhuhu
commited on
Commit
·
0f2f299
1
Parent(s):
a3059ba
为IP检测功能加入错误恢复
Browse files
utils.py
CHANGED
|
@@ -287,10 +287,17 @@ def replace_today(prompt):
|
|
| 287 |
def get_geoip():
|
| 288 |
response = requests.get('https://ipapi.co/json/', timeout=5)
|
| 289 |
data = response.json()
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
|
|
|
|
|
|
|
|
|
| 293 |
else:
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
def get_geoip():
|
| 288 |
response = requests.get('https://ipapi.co/json/', timeout=5)
|
| 289 |
data = response.json()
|
| 290 |
+
if "error" in data.keys():
|
| 291 |
+
logging.info("无法获取IP地址信息。")
|
| 292 |
+
if data['reason'] == "RateLimited":
|
| 293 |
+
return f"获取IP地理位置失败,因为达到了检测IP的速率限制。聊天功能可能仍然可用,但请注意,如果您的IP地址在不受支持的地区,您可能会遇到问题。"
|
| 294 |
+
else:
|
| 295 |
+
return f"获取IP地理位置失败。原因:{data['reason']}"
|
| 296 |
else:
|
| 297 |
+
country = data['country_name']
|
| 298 |
+
if country == "China":
|
| 299 |
+
text = "**您的IP区域:中国。请立即检查代理设置,在不受支持的地区使用API可能导致账号被封禁。**"
|
| 300 |
+
else:
|
| 301 |
+
text = f"您的IP区域:{country}。"
|
| 302 |
+
logging.info(text)
|
| 303 |
+
return text
|