python – Trying to run Flask app gives Address already in use
python – Trying to run Flask app gives Address already in use
It means theres another services using that port (8080
in this case). Maybe because you forgot close another running Flask app and its using 8080
port.
n
However, you could change the port youre using, for example change it to 4444
like this:
n
if __name__==__main__:n app.run(host=os.getenv(IP, 0.0.0.0), n port=int(os.getenv(PORT, 4444)))n
n
But anyways, I think youd like to know which program is using that part if its not your program. You could use nmap
or netcat
GNU program to check it.
n
Heres the netcat
way (from here):
n
$ sudo netstat -nlp | grep 8080ntcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 125004/nginxn
n
When you got it, Id suggest stop it manually (for example if its nginx
or other HTTP servers, then stop it via service
command or systemctl
if youre using systemd Linux)
n
You can also kill it via command kill
:
n
kill <pid>n
n
You can also kill it via killall
or pkill
, it use a process name instead of its pid:
n
killall/pkill <process name>n
‘
Try to kill all the other processes which are running on your server using this command
n
n
sudo fuser -k xxxx/tcp
n
n
replace xxxx with your port name
‘
python – Trying to run Flask app gives Address already in use
You can get the pid of all running processes having python keyword using the command:
n
n
ps -fA | grep python
n
n
After getting the pids use kill command as follows:
n
n
kill -9 pid
n
n
After running above two commands now run the flask app, it will work fine
Related posts on python :
- What is socket bind Python?
- How do you read a .CSV file into a dictionary in Python?
- How do I downgrade Python from 3.8 to 3.7 Ubuntu?
- How do I normalize data between 0 and 1 in Python?
- How do I remove text from a word in Python?
- What does triple quotes mean in Python?
- What are the two ways to create an empty dictionary in Python?
- TypeError: iteration over a 0-d array Python
- python – How do I visualize a net in Pytorch?
- python – Max retries exceeded with URL in requests