OSError [Errno 48] Address Already in Use: 3 Ways to Fix

Manually specify the port in order to fix this error message

Reading time icon 3 min. read


Readers help support Windows Report. We may get a commission if you buy through our links. Tooltip Icon

Read our disclosure page to find out how can you help Windows Report sustain the editorial team. Read more

oserror [errno 48] address already in use

You get the oserror: [errno 48] address already in use, also known as Python socket error 48, when a process attempts to bind itself to a busy port.

This error is somewhat different than Python runtime error that we covered earlier, so let’s see how we can fix it.

What is socket error 48 address already in use?

  • This error message occurs while using Python.
  • It’s caused because a different process is already using the specified socket.

How do I fix oserror: [errno 48] address already in use?

1. Specify an unused port number for the process

  1. Start the command line.
  2. Add the port number after the above command, so that it becomes: $ python -m SimpleHTTPServer (Port Number)

  3. Make sure to change the port number with the actual port number.

After running the above command, confirm if oserror: [errno 48] address already in use error is gone.

2. Free up the port

  1. Locate and list the processes using the port by running the command below: $ ps -fA | grep python

  2. If successful, you will see the process codes in the argument, looking like the line below: 502 89332 12877 0 3:40PM ttys00 0:00.15 python -m SimpleHTTPServer
  1. From the argument above, if multiple python processes are active, it is easy to spot the process running SimpleHTTPServer.
  2. From the argument above, we can now kill the process with code 89332 to free up the port. Enter the following command to kill this process: kill 89332
    ย 
  3. If the process is not responding, you can also kill the process using the tougher command below: sudo kill -9 PID
  1. The above command sends a standard SIGTERM signal.
  2. Finally, bind the process to the port you just freed up by running the following command: $ python -m SimpleHTTPServer (Port Number)

Remember that you should change the (Port Number) in the command to the actual port number.

After entering the last command above, the process will be created on the free port. This method has proven to repair oserror: [errno 48] address already in use error.

3. Restart Raspberry Pi

  1. Turn off your Raspberry Pi.
  2. Wait for a few moments.
  3. Power it up again.

As mentioned at the beginning of this troubleshooting guide, the process may already be bound to port 800 (the default port) if you ran it before.

You can easily clear the oserror: [errno 48] address already in use by specifying an unused port or freeing up the port that the process is bound to.

By following any of the above-written methods, you should be able to fix the Python socket error 48. Python is prone to errors, and we already covered PermissionError: [Errno 13] permission denied in one of our older guides.

We also have a new guide on Cannot open shared object no such file or directory error, so you might be interested in checking it out.

However, we would appreciate it if you let us know which method worked best for you by leaving us a message in the comments section below.

More about the topics: Error Code, ports

User forum

0 messages