I am trying to make my api to be have public IP using waitress or normal flask connection but I can not.
app = Flask(__name__)
mysql = MySQL()
@app.route('/')
def index():
return "Hello, world!"
if __name__ == "__main__":
# waitress.serve(app=app, host="0.0.0.0", port=5013)
app.run(host="10.0.***", port=5013, debug=True, threaded=True)
I can access it from my machine only. but when I try to access from outside(i.e any phone or tablet) I cant reach it.
While this is possible, you should not use the Flask dev server in production. The Flask dev server is not designed to be particularly secure, stable, or efficient. See the docs on deploying for correct solutions.
The
--host
option toflask run
, or thehost
parameter toapp.run()
, controls what address the development server listens to. By default it runs onlocalhost
, change it toflask run --host=0.0.0.0
(orapp.run(host="0.0.0.0")
) to run on all your machine's IP addresses.0.0.0.0
is a special value that you can't use in the browser directly, you'll need to navigate to the actual IP address of the machine on the network. You may also need to adjust your firewall to allow external access to the port.The Flask quickstart docs explain this in the "Externally Visible Server" section: