Ask coding questions

← Back to all posts
Client IP in Flask.
pumpedupkicks (0)

According to the Flask documentation, you should be able to see the client's IP through request.remote_addr and request.access_route. On replit this seems to return 127.0.0.1 and 35.191.x.xxx which is a Google Cloud IP after I looked it up.

I am looking for the ability to send a Json post request to the server, who will in turn send one back to the client (for this example it's just {key: value})

Any ideas what I'm doing wrong, or other I can achieve this functionality inside python?

from flask import Flask
from flask import request
app = Flask('')
@app.route("/ping", methods=['POST'])
def ping():
  data = request.get_json()
  print("Got a request!")
  print(data)
  print(request.access_route)
  print(request.remote_addr)
  reply = requests.post(request.remote_addr, data = {'key':'value'})
  print(reply)
Comments
hotnewtop
xfinnbar (21)

Replit proxies connections through that 35.191.x.xxx, so this isn't possible. This is to prevent IP logging I believe. What you can do hovever is use a websocket server for two-way communication if you want.

ch1ck3n (1618)

@xfinnbar ohh that's why i had trouble with the IP stuff too