Fix Python Socket Error 48

Socket Error 48 is a python error which is triggered when the process tries to bind itself to a port that is already in use.

Servers

What Causes the “socket.error: [Errno 48] Address already in use” Error?

After brief research, we found the causes to be:

  • Process Bound to Port: Whenever a process is created on the server, a port is used by it to communicate with the internet. The port is like a host that can entertain one guest at a time. However, if you don’t specify a port, the server just creates it on the default port. The next time you create a process, a port has to be specified because the default port is already in use.

Solution 1: Specifying Port Number

The error is mostly triggered when a person tries to bound a specific process to the default port and the default port is already bound to a different process. Therefore, in this step, we will be specifying the port on which the process is to be bounded.

  1. Chances are, you are using the following command to create a process.
     $ python -m SimpleHTTPServer
  2. Instead of this, use this command to create a process.
     $ python -m SimpleHTTPServer (Port Number)
  3. Wait for the process to be created and check to see if the issue persists.

Solution 2: Freeing up the Port

If the port is already in use by a different process, the new process will not be able to function on that port. Therefore, in this step, we will be freeing up the port by terminating the previous process and then running the new one. For that:

  1. Use the following command to list a number of processes using a specific port.
    $ ps -fA | grep python
  2. The command argument will look something like the following lines.
     601 88234 12788 0 9:53PM ttys000 0:00.16 python -m SimpleHTTPServer
  3. Out of this, the process code that we will use to kill is “88234”.
  4. Use the following command to kill the process.
    kill 88234

    Alternatively, you can use the following command to kill it.

    sudo kill -9 PID
  5. You can now bound the process to this port by using the following command.
      $ python -m SimpleHTTPServer (Port Number)
  6. The process will now be created.

Solution 3: Restarting Raspberry Pi (Only For Raspberry Pi)

You can get rid of this error on Raspberry Pi by restarting the Raspberry Pi or by killing the terminal shell. The Raspberry Pi sometimes is unable to kill the processes automatically and triggers this error because of the previous processes already running on the ports.

Kevin Arrows


Kevin is a dynamic and self-motivated information technology professional, with a Thorough knowledge of all facets pertaining to network infrastructure design, implementation and administration. Superior record of delivering simultaneous large-scale mission critical projects on time and under budget.

Expert Tip

Fix Python Socket Error 48

If the issue is with your Computer or a Laptop you should try using Restoro which can scan the repositories and replace corrupt and missing files. This works in most cases, where the issue is originated due to a system corruption. You can download Restoro by clicking the Download button below.

Download Now

I'm not interested

Close