在我的项目中,我希望访问用户的位置/城市,以便能够显示用户位置附近的皮肤科医生,只有当他们单击html页面上的“访问我的位置”按钮时,才会发生这种情况。因此,当用户单击此按钮时,@app.route()将转到app.py,我编写了以下代码。
@app.route('/access')
def my_location():
try:
geoip_data = simple_geoip.get_geoip_data()
return jsonify(data=geoip_data)
except Exception as e:
return render_template('home.html', msg = e)
但是,当执行这段代码时,我会得到以下结果。1:https://i.stack.imgur.com/wRCB0.png
它为什么不向我的国家、城市或其他地方展示呢?如果可能的话请帮忙!
发布于 2022-01-26 11:01:22
这是因为您正在发送localhost地址(Loopback / 127.0.0.0)。尝试提供您的公共IP代替!
from simple_geoip import GeoIP
geoip = GeoIP("your-api-key");
try:
data = geoip.lookup("8.8.8.8") # Replace this with your public IP
except ConnectionError:
# If you get here, it means you were unable to reach the geoipify
# service, most likely because of a network error on your end.
except ServiceError:
# If you get here, it means geoipify is having issues, so the request
# couldn't be completed :(
except:
# Something else happened (non-geoipify) related. Maybe you hit CTRL-C
# while the program was running, the kernel is killing your process, or
# something else all together.
print(data)
https://stackoverflow.com/questions/70862288
复制相似问题