Flask获取远程ip地址为127.0.0.1

通过flask获取到的远程ip地址为:127.0.0.1,解决方法如下:

If there is a proxy in front of Flask, then something like this will get the real IP in Flask:

if request.headers.getlist("X-Forwarded-For"):
   ip = request.headers.getlist("X-Forwarded-For")[0]
else:
   ip = request.remote_addr

参考地址:https://stackoverflow.com/questions/12770950/flask-request-remote-addr-is-wrong-on-webfaction-and-not-showing-real-user-ip

 

posted @ 2019-08-05 10:52  远洪  阅读(2382)  评论(0)    收藏  举报