FIX: Python Socket Error 48: Address already in use

Milan Stanojevic
by Milan Stanojevic
Windows & Software Expert
Milan has been enthusiastic about PCs ever since his childhood days, and this led him to take interest in all PC-related technologies. Before joining WindowsReport, he worked as a front-end web developer. Read more
Affiliate Disclosure
  • Python is a very common programming language used in many of today's programs.
  • The article below will show you how to handle Python Socket Error 48.
  • If you can't handle Python, then maybe you should use a program to convert it into something you know.
  • If you need more general troubleshooting guides, visit our Fix page.
python socket error 48 address already in use
To fix various PC problems, we recommend DriverFix:
This software will keep your drivers up and running, thus keeping you safe from common computer errors and hardware failure. Check all your drivers now in 3 easy steps:

  1. Download DriverFix (verified download file).
  2. Click Start Scan to find all problematic drivers.
  3. Click Update Drivers to get new versions and avoid system malfunctionings.
  • DriverFix has been downloaded by 0 readers this month.

You get the python socket error 48: Address already in use when a process attempts to bind itself to a busy port. Processes on the server connect to the internet via ports, and if you do not specify a port, the default port (8000) is used.

To solve this issue and clear the error, you have to bind the process to an unused port using one of the solutions in this guide.

How do I fix the python socket error 48: Address already in use?

1. Specify an unused port number for the process

  1. If you were creating the process using the following command:
 $ python -m SimpleHTTPServer

Add the port number after the above command, so that it becomes:

 $ python -m SimpleHTTPServer (Port Number)

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

  1. After running the above command, confirm if the python socket error 48 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
  1. 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
  1. 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)

NOTE 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 the python socket error 48.

3. Restart Raspberry Pi

Raspberry Pi cannot kill processes automatically, and so, the processes running on the ports must be ended manually.

This solution is basically the same principle as the above method. If you get the python socket error 48: Address already in use on Raspberry Pi, restarting it can fix the error.

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 python socket error 48: Address already in use by specifying an unused port or freeing up the port that the process is bound to.

If you get the error on Raspberry Pi, simply restart it to repair.

By following any of the above-written methods you should be able to fix the Python Socket Error 48.

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.

Frequently Asked Questions

This article covers:Topics: