Flask Error: [Errno 98] Address already in use

While running a Flask application initially, an error that popped up, again and again, is :[Errno 98] Address already in use

The flask error is quite clear, but the resolution was not!

When you are running FLASK and building an application, you may forget, or sometimes you could not close that application. Thus re-running your application on localhost may end up in this error.

I usually work on Jupyter Notebook on my MAC and sometimes on the python terminal. I tried to find the running session and kill those but eventually ended up killing my up-and-running Jupyter Notebook session. Well, if you have been there and done that, you will know how it feels.

What worked for me is changing the port every time I ran my application. It worked just fine!

so instead of doing this:

if __name__ == '__main__': 
app.run(use_reloader=False, debug=True)

You can do this:

if __name__ == '__main__': 
port = 5000 + random.randint(0, 999)
url = "{0}".format(port)
app.run(use_reloader=False, debug=True, port=port)

Ignore the print statements. I just wanted to see how it is working! Also, once you have your application in a working state, you can go back to the first one.

If you are looking for some tips to deploy your Flask application, here is an example:

Deploy Your First Machine Learning Model using Flask

Please clap once if it really helps you to fix your problem.

Thank You for Reading!

Originally published at https://oindrilasen.com on December 4, 2020.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store