Posts Tagged ‘remote_addr’

Heroku: strange client IP addresses

November 3, 2013 Leave a comment

In Flask, you can ask the client’s IP address with request.remote_addr . If you try to print this value on Heroku, you will get strange IP addresses that have nothing to do with the client’s IP.

It’s because your app. at Heroku is behind proxies and your app. will see the proxies’ IP, not the real client’s IP.

Fortunately there is a fix for this problem here: You just need to insert these two lines in the production code:

from werkzeug.contrib.fixers import ProxyFix
app.wsgi_app = ProxyFix(app.wsgi_app)
Categories: python Tags: , , ,