Forums

Flask remote_addr persists between computers

Hi,

I have a Flask app that uses request.remote_addr to see the external IP address of the machine making the connection. (This I do, because it's a system for redirecting to the IP of a local Raspberry Pi).

There's only one problem. The request object with the remote_addr never seems to be refreshed. So, I go to work and go to the page which simply has the code:

@app.route('/test', methods=["GET"])
def test():
    return str(request.remote_addr)

And it continues to give me the IP address of my home computer. How do I get Flask to 'throw away' the old request object and give me a new one?

Thanks, Robert

What's the IP address? Could it actually be the IP address of our load balancer? you may have to inspect the request differently to find the real source ip, we set some headers called X-Forwarded-For...

10.86.241.99 - which is, I now realise, a private IP address... which much therefore be your load balancer...

Do you know what I need to do to get the 'real' source IP address from Flask?

request.headers.get('X-Forwarded-For')?

Works perfectly :-)

Thanks very much