0

When running this command

python -m SimpleHTTPServer 8000

I am getting below listed error

socket.error: [Errno 98] Address already in use

sshashank124
  • 31,495
  • 9
  • 67
  • 76
  • 2
    Some other process running on your system is already listening on port 8000. – metatoaster Jan 03 '20 at 04:39
  • maybe open in web browser `localhost:8000` to see what program uses this port – furas Jan 03 '20 at 04:44
  • 1
    BTW: sometimes system (Windows/Linux/MacOS) blocks port for some short time after closing program and you have to wait before you can run the same program again. – furas Jan 03 '20 at 04:46

3 Answers3

1

That message clearly tells that port 8000 is already in use, just use another port or kill another process that uses port 8000 first.

Nur Faizin
  • 171
  • 6
1

Sounds like a process is already using that port. So you will want to find which process is listening on that port and kill it

Linux

To check which process is using the port on Linux, you can install net-tools and use the command: netstat -ltnp | grep -w ':[Port Number]'

Then using the PID (Process ID) you got from the previous command you can kill the program with the following:

kill -9 [PID]

Windows

If you are on Windows you can find the process by using:

netstat -a -n -o | find "[Port Number]"

Then you can just hop into Task Manager and kill the process.

I hope this helps

  • I'd like to comment the Linux part: `netstat` is deprecated (since 2011?) - use `ss` instead. On recent systems it is not even installed by default: https://stackoverflow.com/questions/11763376/difference-between-netstat-and-ss-in-linux. `kill -9` is a to be used only when regular ways to stop a process fail. It does not give the process a chance to clean up. Another reason is if the killed process is part of a systemd service, it might get restarted. – VPfB Jan 03 '20 at 06:56
  • Thank you for your suggestion and help my issue got resolved by installing some ipks. – Sanjay Poptani Jan 03 '20 at 07:48
0

I am not sure which python version you are using but please check SimpleHTTPServer — Simple HTTP request handler python doc

I have tried :: python -m http.server 8000 --bind 127.0.0.1 it worked instead of SimpleHTTPServer