首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用烧瓶-Simple-GeoAPI获取用户位置

如何使用烧瓶-Simple-GeoAPI获取用户位置
EN

Stack Overflow用户
提问于 2022-01-26 10:52:14
回答 1查看 529关注 0票数 1

在我的项目中,我希望访问用户的位置/城市,以便能够显示用户位置附近的皮肤科医生,只有当他们单击html页面上的“访问我的位置”按钮时,才会发生这种情况。因此,当用户单击此按钮时,@app.route()将转到app.py,我编写了以下代码。

代码语言:javascript
运行
复制
@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

它为什么不向我的国家、城市或其他地方展示呢?如果可能的话请帮忙!

EN

回答 1

Stack Overflow用户

发布于 2022-01-26 11:01:22

这是因为您正在发送localhost地址(Loopback / 127.0.0.0)。尝试提供您的公共IP代替!

代码语言:javascript
运行
复制
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)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70862288

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档