Skip to content

Fix offline parse ip info #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions backend/app/utils/request_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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%可用

Expand Down Expand Up @@ -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


Expand Down