Skip to content

Commit 882dc7b

Browse files
Seluj78supalarry
authored andcommitted
Fixed ip lookup fail
1 parent 23cf536 commit 882dc7b

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

backend/PyMatcha/routes/api/profile/edit.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
import datetime
2020

2121
import Geohash
22+
import requests
2223
from flask import Blueprint
2324
from flask import render_template
2425
from flask import request
2526
from flask_jwt_extended import current_user
2627
from flask_jwt_extended import jwt_required
27-
from ip2geotools.databases.noncommercial import DbIpCity
2828
from PyMatcha.models.user import get_user
2929
from PyMatcha.utils import hash_password
3030
from PyMatcha.utils.confirm_token import generate_confirmation_token
@@ -156,9 +156,11 @@ def edit_geolocation():
156156
if lat and lng:
157157
current_user.geohash = Geohash.encode(lat, lng)
158158
else:
159-
response = DbIpCity.get(ip, api_key="free")
160-
lat = response.latitude
161-
lng = response.longitude
159+
response = requests.get(
160+
f"http://api.ipstack.com/{ip}?access_key=b5f9be2253823006b478da121d1c855b&format=1"
161+
).json()
162+
lat = response["latitude"]
163+
lng = response["longitude"]
162164
current_user.geohash = Geohash.encode(lat, lng)
163165
current_user.save()
164166
return Success("New location sucessfully saved.")

backend/requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ pre-commit==2.7.1
2626

2727
lorem==0.1.1
2828
future==0.18.2
29-
ip2geotools==0.1.5
30-
29+
requests==2.24.0
3130
argon2-cffi==20.1.0
3231

3332
geopy==2.0.0

0 commit comments

Comments
 (0)