From d2927684322dc01edc0118a69a7ac4c233e5e95d Mon Sep 17 00:00:00 2001 From: Wu Clan Date: Sun, 11 Jun 2023 12:49:46 +0800 Subject: [PATCH] Fix offline parse ip info (#112) * Fix get info subscript * Fix return typing --- backend/app/utils/request_parse.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/app/utils/request_parse.py b/backend/app/utils/request_parse.py index 0b29e10d..973a8e1a 100644 --- a/backend/app/utils/request_parse.py +++ b/backend/app/utils/request_parse.py @@ -47,7 +47,7 @@ async def get_location_online(ip: str, user_agent: str) -> dict | None: @sync_to_async -def get_location_offline(ip: str) -> str | None: +def get_location_offline(ip: str) -> list[str] | None: """ 离线获取 ip 地址属地,无法保证准确率,100%可用 @@ -79,8 +79,8 @@ async def parse_ip_info(request: Request) -> tuple[str, str, str, str]: location_info = await get_location_offline(ip) if location_info: country = location_info[0] if location_info[0] != '0' else None - region = location_info[1] if location_info[1] != '0' else None - city = location_info[2] if location_info[2] != '0' else None + region = location_info[2] if location_info[2] != '0' else None + city = location_info[3] if location_info[3] != '0' else None return ip, country, region, city