Where cat I get info of the Server IP that flask is running on?
app.config['SERVER_NAME'] returns None, any other options?
SERVER_NAME is supposed to be set by you, not the other way around. You could always use standard Linux tools to get the server ip, some form of ip addr show dev eth0.
This is more appropriate as a question on http://serverfault.com/, it's not Flask related.
Don't use the bugtracker as a support forum.
Sorry folks I still believe this is a BUG, every framework has a way to tell the application layer the identity of the server that is running on. I have 10 servers running flask, if there is an event or crash I need to log the IP address of the faulty server
Similar logic in Java Servlet:
HttpServletRequest.getLocalAddr() - the server's IP address as a string
HttpServletRequest.getLocalName() - the name of the server recieving the request
HttpServletRequest.getServerName() - the name of the server that the request was sent to
HtppServletRequest.getLocalPort() - the port the server recieved the request on
HttpServletRequest.getServerPort() - the port the request was sent to
HttpServletRequest.getContextPath() - the part of the path that identifies the application
Why don't you store an identifier in your config file? That could be much more meaningful anyway than just an ip address.
But if you are in a request context you can simply get the requested URL (and/or parts of it) from there....
I don't think it's possible to recieve the server's IP address through the WSGI interface (the equivalent to servlet in Java, i think). If you find another Python WSGI framework which is able to do that, then it certainly would be possible in Flask. Some alternative data that might be equally useful for logging:
flask.request.host, which is basically the host header.flask.request.headerspath, script_root, url, base_url, url_root on the flask.request object, see http://flask.pocoo.org/docs/0.10/api/#flask.Request.path@ThiefMaster
That's currently my hack. I'm using socket.gethostname() to populate a field on my config file, but this solely gives me the main IP address of the server. I have multiple IP address so I still don't know the IP address being used to serve a particular request
How would flask know the IP your webserver is listening on? I don't think WSGI passes this information to the app.
Most helpful comment
Sorry folks I still believe this is a BUG, every framework has a way to tell the application layer the identity of the server that is running on. I have 10 servers running flask, if there is an event or crash I need to log the IP address of the faulty server
Similar logic in Java Servlet:
HttpServletRequest.getLocalAddr() - the server's IP address as a string
HttpServletRequest.getLocalName() - the name of the server recieving the request
HttpServletRequest.getServerName() - the name of the server that the request was sent to
HtppServletRequest.getLocalPort() - the port the server recieved the request on
HttpServletRequest.getServerPort() - the port the request was sent to
HttpServletRequest.getContextPath() - the part of the path that identifies the application