0

I am doing plotly dash, and sometimes not matter how many other ports I change to use, it always give me below error. Any reason? I even shutdown jupyter notebook and re-launch it and I still got same error. so I am desperate somehome. Thanks for your help.

OSError: Address 'http://127.0.0.1:8052' already in use. Try passing a different port to run_server.


if __name__ == "__main__":
    app.run_server(mode='external',debug=True,port=8052)

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_23784/3219569651.py in <module>
      1 if __name__ == "__main__":
      2     #app.run_server(mode='inline',debug=True,port=8051)
----> 3     app.run_server(mode='external',debug=True,port=8052)

~\miniconda3\envs\dash_project\lib\site-packages\jupyter_dash\jupyter_app.py in run_server(self, mode, width, height, inline_exceptions, **kwargs)
    317                 )
    318 
--> 319         wait_for_app()
    320 
    321         if JupyterDash._in_colab:

~\miniconda3\envs\dash_project\lib\site-packages\retrying.py in wrapped_f(*args, **kw)
     47             @six.wraps(f)
     48             def wrapped_f(*args, **kw):
---> 49                 return Retrying(*dargs, **dkw).call(f, *args, **kw)
     50 
     51             return wrapped_f

~\miniconda3\envs\dash_project\lib\site-packages\retrying.py in call(self, fn, *args, **kwargs)
    210                 if not self._wrap_exception and attempt.has_exception:
    211                     # get() on an attempt with an exception should cause it to be raised, but raise just in case
--> 212                     raise attempt.get()
    213                 else:
    214                     raise RetryError(attempt)

~\miniconda3\envs\dash_project\lib\site-packages\retrying.py in get(self, wrap_exception)
    245                 raise RetryError(self)
    246             else:
--> 247                 six.reraise(self.value[0], self.value[1], self.value[2])
    248         else:
    249             return self.value

~\miniconda3\envs\dash_project\lib\site-packages\six.py in reraise(tp, value, tb)
    717             if value.__traceback__ is not tb:
    718                 raise value.with_traceback(tb)
--> 719             raise value
    720         finally:
    721             value = None

~\miniconda3\envs\dash_project\lib\site-packages\retrying.py in call(self, fn, *args, **kwargs)
    198         while True:
    199             try:
--> 200                 attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
    201             except:
    202                 tb = sys.exc_info()

~\miniconda3\envs\dash_project\lib\site-packages\jupyter_dash\jupyter_app.py in wait_for_app()
    310                     host=host, port=port, token=JupyterDash._token
    311                 )
--> 312                 raise OSError(
    313                     "Address '{url}' already in use.\n"
    314                     "    Try passing a different port to run_server.".format(

OSError: Address 'http://127.0.0.1:8052' already in use.
    Try passing a different port to run_server.

roudan
  • 3,082
  • 5
  • 31
  • 72
  • 1
    try `fuser -k 8052/tcp` to kill the process on that port first because that port is already used – A l w a y s S u n n y Jan 24 '22 at 17:38
  • 1
    It is probably a zombie from a prior run. Find out what app is listening on that port: https://stackoverflow.com/questions/48198/how-can-you-find-out-which-process-is-listening-on-a-tcp-or-udp-port-on-windows – JonSG Jan 24 '22 at 17:39
  • @AlwaysSunny I think they are using some version of Windows (judging from the paths), – JonSG Jan 24 '22 at 17:41
  • where to input this fuser -k 8052/tcp? Thanks Sunny – roudan Jan 24 '22 at 17:44
  • Hi Jon, I did this in powershell, Get-NetTCPConnection -LocalPort 8051 | Format-List and got this: LocalAddress : 127.0.0.1 LocalPort : 8051 RemoteAddress : 0.0.0.0 RemotePort : 0 State : Listen AppliedSetting : OwningProcess : 4436 CreationTime : 1/24/2022 10:41:32 AM OffloadState : InHost – roudan Jan 24 '22 at 17:44
  • Hi Guys, I solved it, it is not related the port issue. It is related to duplicated tab name/id when creating tab. so changing to use different id solving the issue. Thank you guys. I appreicate it. – roudan Jan 24 '22 at 18:09

1 Answers1

1

As a workaround, it is possible to just add a new port in the PlotlyDash app.run() command:

app.run(port=8051)

However, that is not so clean and does not solve the problem of "hanging" or "left-over" ports... A better solution is to identify and kill the left-over processes, thus freeing up the port.

On Mac OSX, perform these steps:

  1. Find out what is running on port 8050 (or whichever is open/occupied) by using the command in the Terminal: lsof -i :8050
  2. Identify the PID (Process IDs) running on that port from the output lsof
  3. Kill the process(es), using the command kill <PID>

On Windows CMD, perform these steps:

  1. Find out what is running on port 8050 (or whichever is open/occupied) by using the command in Windows CMD: netstat -aon | find "8050"
  2. Identify the PID (Process IDentifier) running on that port
  3. Kill the process(es), using the command taskkill /PID <PID>
stephinity
  • 576
  • 5
  • 6