flaskazure-webapps

Flask Web App + Azure Web App = HTTP pings on port: 8000, failing site start


When I deploy my simple webpage in Azure, I get this error.

2024-08-21T00:42:17.637Z ERROR - Container flashapp-test_0_3f696445 didn't respond to HTTP pings on port: 8000, failing site start. See container logs for debugging.

Here is my app.py

from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello():
    return 'Azure Web App Running'

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

I've tried everything, and I can't get past this error.

I have variables set up for port 8000. I can change the port, but I get the same error.

I've created new Azure Web Apps and have the same problem. I'm sure its simple.


Solution

  • The code you provided is actually the reason you're encountering the error message.

    In your code, you have app.run(host='0.0.0.0', debug=True). This line tells Flask to run on any available interface (0.0.0.0) and enables debug mode. However, in Azure, you shouldn't specify the port because Azure assigns ports dynamically.

    The if __name__ == '__main__': block is typically used for local development. When you deploy your app to Azure, this block doesn't get executed. Azure has its own process for starting the application.

    Corrected code for deployment to Azure:

    from flask import Flask
    
    app = Flask(__name__)
    
    @app.route('/')
    def hello():
        return 'Azure Web App Running'
    

    With these changes, your Flask app should listen on the Azure-assigned port and hopefully start successfully.