26

Following plotly dash getting started guide but when trying to run python app.py get message:

OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions

Seems the default address: http://127.0.0.1:8050/ is already being used. How can the default port be changed so I can get this to work?

Vlad
  • 3,058
  • 4
  • 25
  • 53
  • generally open ports are 8124,8125,8126. You can google common open ports to make sure you don't try to take one from a major application. 8888 is good but jupyter notbooks uses that one often as well as Ambari if you are working with cloud computing stuff. – lwileczek Feb 09 '18 at 18:02

6 Answers6

37

As we can see in Dash.run_server method definition, port can be passed as parameter:

def run_server(self,
               port=8050,
               debug=True,
               threaded=True,
               **flask_run_options):
    self.server.run(port=port, debug=debug, **flask_run_options)

So, if you need to use another port:

if __name__ == '__main__':
    app.run_server(debug=True, port=8051) # or whatever you choose
Oleh Rybalchenko
  • 6,998
  • 3
  • 22
  • 36
  • If anyone wants to know which alternative port is available on a Windows 10 machine, type `netstat -ab` in your command line as an administrator and the ports that show the state as `LISTENING` are the ones available. More info here: https://www.alphr.com/how-to-check-which-ports-open-windows-10-pc/ – Azurespot Mar 10 '22 at 22:16
1

Note that in Julia, you can change the port by specifying the port number in the run_server arguments without specifying "port=". For example,

run_server(app, "0.0.0.0", 8000, debug = true)
AaronJPung
  • 1,105
  • 1
  • 19
  • 35
1

You can also set the environment variable PORT in your terminal before launching the Dash app:

https://github.com/plotly/dash/blob/c77912a3183adfccfd4ef84df91eca7fa9c7d543/dash/_configs.py#L34

tash
  • 711
  • 5
  • 13
0

In the place of port = 8050 type your own port number

0

I was running it on a Jupyter notebook, and all I had to do was go to runtime and select factory reset runtime, pip install all dependencies (like jupyter-dash), and I was good to go...

0

As described in Oleh's answer above, it is possible to just define a new port in the PlotlyDash app.run() command.

However, that does not actually solve the problem of cleaning up "hanging" or "left-over" ports opened up by PlotlyDash... A more clean solution is to identify and kill the left-over processes, thus freeing up the port. Then PlotlyDash can be re-run/started.

On Mac OSX / Linux, 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 IDentifier) running on that port from the output of the lsof command
  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