localhost:5000: Flask, .NET and the macOS AirPlay Clash

localhost:5000 is the address flask run uses, and ASP.NET Core's Kestrel falls back to it when nothing else sets a URL. On a Mac there is a twist: AirPlay Receiver listens on 5000 too, so Flask cannot start or the browser gets a 403 from macOS. Turn AirPlay Receiver off or use 5001.

Who answers on port 5000
ProgramSign it is the one answeringFix
Flask dev serverTerminal shows Running on http://127.0.0.1:5000Normal; open that URL
macOS AirPlay Receiver403 Forbidden with a Server: AirTunes headerTurn off AirPlay Receiver, or run Flask on 5001
ASP.NET Core Kestreldotnet run prints Now listening on: http://localhost:5000Set --urls or launchSettings.json

Updated

Most port 5000 problems on a Mac are not your code at all. Since macOS Monterey the system's AirPlay Receiver has used the port, and because it answers HTTP requests, the browser shows an error page that looks like it came from your app. Checking the response headers settles it in seconds.

Check who is answering on 5000

Read the Server header and the listening process

A Server: AirTunes line means macOS answered; lsof names the process that holds the port.

curl -sI http://localhost:5000 | grep -i '^server'
lsof -nP -iTCP:5000 -sTCP:LISTEN

Run Flask on 5001 for everyone on the project

python-dotenv lets flask run read .flaskenv, so the port travels with the repository.

# .flaskenv
FLASK_APP=app.py
FLASK_RUN_PORT=5001

# then
flask run

The AirPlay Receiver clash, explained

Apple added AirPlay to Mac in macOS Monterey, and the receiver listens on TCP port 5000 for streams from other devices. Flask had used 5000 for years, so many developers updating macOS found that flask run failed with 'Address already in use', or that the browser showed a 403 page that Flask never sent.

Two fixes work. Turn AirPlay Receiver off if you never stream to your Mac, or adopt 5001 or another port for Flask in your project's .flaskenv so the whole team avoids the clash.

Refused to connect: Flask and .NET checks

Flask: FLASK_APP must point at your app, or flask run cannot find it and exits. With debug mode on, a syntax error stops the reloader, so the terminal shows a traceback and the port closes.

.NET: dotnet run uses the first profile in launchSettings.json, which may set a different port and HTTPS only. If the browser warns about the certificate, run dotnet dev-certs https --trust once.

If you only need a business website rather than a local project, We.Inc builds and previews the site in your browser, so there is no local server or port to manage.

How it works

  1. Run curl -I http://localhost:5000 and read the Server header in the reply.
  2. If it says AirTunes, it is macOS: disable AirPlay Receiver or move your app.
  3. If nothing answers, start your Flask or .NET app and read the address it prints.
  4. If startup fails with 'address already in use', find the process with lsof or netstat and stop it.

Tips

  • On recent macOS, AirPlay Receiver lives in System Settings, General, AirDrop and Handoff. Switching it off frees port 5000 straight away.
  • Run Flask on a different port with flask run --port 5001; app.run(port=5001) does the same for scripts started with python app.py.
  • For ASP.NET Core, the profile in Properties/launchSettings.json usually overrides 5000 with a random port. Read the 'Now listening on' lines rather than guessing.
  • Port 5001 is Kestrel's HTTPS default, so on a .NET machine pick 5002 or higher for Flask to avoid a second clash.

Frequently asked questions

Why does localhost:5000 give 403 Forbidden on my Mac?

macOS AirPlay Receiver is listening on port 5000 and refusing the request. Your app either is not running or could not bind the port. Turn off AirPlay Receiver in System Settings, or run your app on another port.

How do I change the Flask port?

Use flask run --port 5001, set the FLASK_RUN_PORT environment variable, or call app.run(port=5001) when you start the app with python. Pick any free port above 1024.

What uses port 5000 on Windows?

Nothing built into Windows by default, so check with netstat -ano | findstr :5000 and look up the PID in Task Manager. It is often a forgotten Flask or .NET dev server.

Why can't another computer open my Flask app on 5000?

The Flask dev server listens on 127.0.0.1 unless you start it with flask run --host=0.0.0.0. Only do that on a network you trust, because the dev server is not built for public traffic.

Is localhost:5000 the same as localhost:5001?

No, they are separate ports and can belong to separate programs. In .NET projects 5001 is often the HTTPS address and 5000 the plain HTTP one.

Related: localhost:8000, 403 Forbidden, localhost:3000, HTTP status codes.

Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.

More in Guides

Product

Who It's For

Features

Resources

Company

View Sitemap