Get IP Address of Request in Flask App on Glitch.com

434 views Asked by At

I have a Flask App running on Glitch. I want to find a way to get the IP address of the client who is requesting data from my website. Is there a way to do that? And before you mark this question as a duplicate, I tried request.environ['REMOTE_ADDR'], request.environ.get('HTTP_X_REAL_IP', request.remote_addr), request.remote_addr, and so many more. All of those show 127.0.0.1, which is the server's IP Address. I am looking for a specific way on Glitch. Any help would be appreciated. Thanks in advance!

Code:

# Imports

app = Flask(__name__)

@app.route("/")
def index():
    # Stuff

if __name__ == "__main__":
  app.run()
1

There are 1 answers

1
Seyi Daniel On

I don't why remote_addr didn't work, did you use it this way:

# Imports
from flask import request
from flask import jsonify

app = Flask(__name__)

@app.route("/")
def index():
     ipdr = {'ipdr': request.remote_addr}
     return jsonify(ipdr), 200

if __name__ == "__main__":
app.run()