pythonplotly-dash

why always Address 'http://127.0.0.1:8050' already in use?


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.


Solution

  • 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>