Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
A
aisbf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexlab
aisbf
Commits
ddddc6d1
Commit
ddddc6d1
authored
Apr 24, 2026
by
Stefy Lanza (nextime / spora )
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix IP geolocation service: change to HTTPS and add IP validation
parent
feafe0db
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
2 deletions
+10
-2
geolocation.py
geolocation.py
+10
-2
No files found.
geolocation.py
View file @
ddddc6d1
import
asyncio
import
httpx
import
ipaddress
from
typing
import
Dict
,
Optional
# Global cache for IP -> country mappings
...
...
@@ -10,12 +11,19 @@ async def get_ip_country(ip: str) -> Optional[str]:
Returns country code (e.g., 'IL') or None if failed.
"""
# Validate IP address format
try
:
ipaddress
.
ip_address
(
ip
)
except
ValueError
:
_ip_country_cache
[
ip
]
=
None
return
None
if
ip
in
_ip_country_cache
:
return
_ip_country_cache
[
ip
]
try
:
async
with
httpx
.
AsyncClient
(
timeout
=
5.0
)
as
client
:
response
=
await
client
.
get
(
f
"http://ipapi.co/{ip}/country/"
)
response
=
await
client
.
get
(
f
"http
s
://ipapi.co/{ip}/country/"
)
if
response
.
status_code
==
200
:
country
=
response
.
text
.
strip
()
.
upper
()
_ip_country_cache
[
ip
]
=
country
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment