Forums

Bash says my flask is running on port XXXX but that same flask says port YYYY is already in use

Im on a free account of PA, my computer is windows 11 pro and I only have one flask (I believe) and one Bash (for sure). My latest Bash response says this:

17:18 ~/mysite $ flask run --host=#.#.#.# --port=XXXX
 * Serving Flask app '/home/(blahblah)/mysite/flask_app.py' (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: off
 * Running on all addresses (0.0.0.0)
   WARNING: This is a development server. Do not use it in a production deployment.
 * Running on http://###.#.#.#:XXXX
 * Running on http://##.#.#.###:XXXX (Press CTRL+C to quit)
echo $$
~/mysite $ echo $$   
echo %errorlevel%
~/mysite $ echo %errorlevel%

But when I go to update, save, reload and Run my flask, it says this below the editor:

 * Debug mode: on
Address already in use
Port YYYY is in use by another program. Either identify and stop that program, or start the server with a different port.
Traceback (most recent call last):
  File "/.../local/.../python3.10/site-packages/.../serving.py", line 908, in prepare_socket
    s.bind(server_address)
OSError: [Errno 98] Address already in use

Im very new to this but if I understand correctly, my Bash is commanding my flask to run on port XXXX but then when I go to test my flask (click ">>>Run") my flask is trying to go out on a completely different port (YYYY) which would not be possible if my Bask is already running it through XXXX. I even tried to add app.run(debug=True,port=XXXX) and then I get an error saying theres already a program running there... yea THIS! Or so I thought haha. Please help.

Also, ever since my Bash said my flask is successfully running on port XXXX, the "$" isnt green anymore. What does that mean? Thanks all!!!

[edit by admin: formatting]

The flask run command is only really meant for when you're testing a Flask site on your own machine -- as it says,

This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.

To use a production WSGI server, just set up the site on the "Web" page inside PythonAnywhere. That will set up our system so that your site is being run safely for use on the public Internet. This help page has details on what you need to do on the "Web" page.