Search code examples
pythonflaskmapr

Unable to open url for flask application


I'm installed MapR Sandbox using virtual box. From putty I'have connected mapr sandbox which is installed in centos. In this system developed a flask application and ran it. In terminal it is showing

Running on http://127.0.0.1:5000/

but when I come out if the sandbox and open above url it is showing This site can’t be reached

Can we run a application out side the sandbox which is developed in sandbox? If yes then how i can open above url?

I can see the hbase web url which is running from mapr .


Solution

  • In default, you web server only visable on your current computer (i.e. the virtual one in your sandbox). If you want to visit outside the sandbox, you need to edit the host:

    if __name__ == '__main__':
        app.run(host='0.0.0.0')
    

    or:

    flask run host=0.0.0.0
    

    Then go to http://<your virtual os's public IP>:5000/
    Here is documentation form Quick Start

    Externally Visible Server If you run the server you will notice that the server is only accessible from your own computer, not from any other in the network. This is the default because in debugging mode a user of the application can execute arbitrary Python code on your computer.

    If you have the debugger disabled or trust the users on your network, you can make the server publicly available simply by adding --host=0.0.0.0 to the command line:

    flask run --host=0.0.0.0
    This tells your operating system to listen on all public IPs.