Why Python-Flask application run when add the port in the startup command

Devanshu Soni 0 Reputation points
2024-03-06T18:31:00.72+00:00

I hosted a Linux web app and deployed a Python-Flask application on it. Initially, the web app was functioning properly, but it suddenly stopped and started displaying an application error. After examining the logs, I discovered that changing my startup command from "python application.py" to "python application.py --port 5000" in the configuration resolved the issue, and the application began running smoothly again. I'm curious why it was functioning correctly before without specifying the port in the startup command, but now it requires it.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,902 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Grmacjon-MSFT 16,101 Reputation points
    2024-03-08T22:56:36.2+00:00

    Hello @Devanshu Soni thanks for the question and sharing the solution that worked for you.

    There are two main reasons why your Flask application initially ran without specifying a port and then suddenly required it.

    By default, Flask applications launched with just python application.py used to run on port 5000. This behavior might have changed in a recent update to Flask or your Python environment. This is a reasonable change as using a specific port avoids conflicts with other applications potentially running on the same machine and port combination.

    Secondly, it's possible that your initial configuration (without specifying a port) might have been implicitly relying on a default port setting defined in a web server configuration file (e.g., Apache, Nginx). If this configuration was changed or removed, the default port for Flask wouldn't be automatically picked up anymore.

    In a production environment, its good to always specify the port in your startup command (python application.py --port 5000) to avoid any unexpected behavior due to changes .This ensures your application consistently listens on the intended port.

    Hope that helped.

    Best,

    Grace

    0 comments No comments