Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask: OSError: [Errno 98] Address already in use - but why? [duplicate]

I have a very simple code here:

from flask import Flask

app = Flask(__name__)

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

I have run it the first time and it worked, then ctrl+c didn't work so I just killed python terminal myself. Then I tried to run it again and I get an error:

 * Serving Flask app "untitled1" (lazy loading)
 * Environment: production
 WARNING: Do not use the development server in a production 
 environment.
 Use a production WSGI server instead.
 * Debug mode: on
 Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/usr/lib/python3/dist- 
 packages/spyderlib/widgets/externalshell/sitecustomize.py", line 699, 
 in runfile
 execfile(filename, namespace)
 File "/usr/lib/python3/dist- 
 packages/spyderlib/widgets/externalshell/sitecustomize.py", line 88, 
in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'), 
namespace)
File "/home/teoman/Desktop/flaskapp/untitled1.py", line 13, in 
<module>
app.run(debug=True)
File "/home/teoman/.local/lib/python3.5/site-packages/flask/app.py", 
line 943, in run
run_simple(host, port, self, **options)
File "/home/teoman/.local/lib/python3.5/site- 
packages/werkzeug/serving.py", line 795, in run_simple
s.bind(get_sockaddr(hostname, port, address_family))
OSError: [Errno 98] Address already in use

I have found similar questions asked but I couldn't understand it because of the solutions were also complicated, I'm very new to Flask app (like ten minutes), I use Linux Mint MATE.

NOTE: localhost:5000 works fine still I do not have any python command-lines open working Flask app.

like image 995
teoman Avatar asked Jun 10 '18 13:06

teoman


People also ask

Why can't I start flask on 8080 port?

Maybe because you forgot close another running Flask app and it's using 8080 port. address already in use means that the server couldnt be started, because another server runs on that port. Check if your program already runs, if it does so, terminate it. Also you can look at the active tcp servers using tcpview on windows systems.

Is it possible to run a flask app in console?

See the docs here and here Are you trying to run a Flask app in a console? Don't do that. It won't work. Our console servers are not able to server web applications.

How to get the PID of a running process in flask?

You can get the pid of all running processes having python keyword using the command: After running above two commands now run the flask app, it will work fine I'm not sure that this answers the original question? You can simply use host and port parameter of run function to set another host and port .so that you can test your application.

How to fix [errno 98] address already in use error?

This happens when you use "ctrl+z" when flask app is running. When you run your flask app again in same terminal you get the error "OSError: [Errno 98] Address already in use" When we use "ctrl+z" the process runs in background, we then bring it to the foreground using the "fg" and then use "ctrl+c" to stop it


1 Answers

It seems like some other application is using port 5000. You can use netstat to see which processes are using ports with the command below:

netstat -tulpn

You can also check common apps using port 5000 by visiting this page

like image 188
caki Avatar answered Sep 21 '22 09:09

caki