0

The code I currently have is something like this:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def main():
    return "welcome to my page"


app.run(debug=True, host="0.0.0.0", port=8080)

When I try to run the code on Pychar I get the following results:

"C:\Users\radbo\AppData\Local\Programs\Python\Python39\python.exe C:/Users/radbo/yay.py
 * Serving Flask app "yay" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 161-701-749
 * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)

"

Instead this is returned:

Hmmm… can't reach this page It looks like the webpage at http://0.0.0.0:8080/ might be having issues, or it may have moved permanently to a new web address.
ERR_ADDRESS_INVALID

My question is as follows: Is my server connectable or does it not exist?

Vlusion
  • 79
  • 1
  • 14

1 Answers1

0

In Flask (and other server technologies) 0.0.0.0 is a convention that means "bind on all addresses". However, 0.0.0.0 is not a valid address for your browser to reach a destination.

That means your flask server will bind to, among any other addresses your system has, to its loopback address 127.0.0.1 (which the alias localhost will almost always point to).

So in your browser, you should use http://127.0.0.1:8000 or http://localhost:8000

If your machine has other IP addresses associated with it, you can also reach it on those IP addresses, provided that firewall rules permit the traffic.

Note that using 0.0.0.0 means that your webserver will also respond to requests that come from other clients on your network, particularly when using debug=True which can pose security risks if exposed, which obviously may not be desirable. If you're only going to use the webapp locally on your own computer, consider using host=127.0.0.1

reference

sytech
  • 29,298
  • 3
  • 45
  • 86