Forums

Can not run Flask Script due to Address already in use error

When I try to run my Flask main script I get following error

  • Running on http://127.0.0.1:5000/ Traceback (most recent call last): File "flask_app.py", line 298, in <module> app.run(host='127.0.0.1',port=5000,debug=True) File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 772, in run run_simple(host, port, self, **options) File "/usr/local/lib/python3.4/dist-packages/werkzeug/serving.py", line 706, in run_simple test_socket.bind((hostname, port)) OSError: [Errno 98] Address already in use

This is important for me because I create database while running the script on bash. I changed port number so it worked but it is not a permanent solution I tried to see process by top and kill that port using app but didn't have permission. So what is your advice for solution.

Thank you

Hi there, this is a common question, so I decided to write up a wiki page on how to use Flask, which talks about app.run() and database setup at the end.

Let me know if it answers your question, and whether you think it's a useful how-to guide? https://www.pythonanywhere.com/wiki/Flask

what about this: im using flask script,so im running the file using runserver...moreover, my app is in a factory function inside a package then it is called and run using manage.run() in my project directory....ie

mysite/

 - app/

       __init__.py( with the factory function-  app = __flask__)

 -manage.py   (has manager=Manager(app)  )

the wsgi file...what do i import from...? from manage import manager as application or from app import app

you can simply use in terminal : ps aux | grep "your_mail_app.py" and get PID of that and say : kill -9 PID

@kelvin probably from app import app