I cannot access a web server on localhost port 5000 on macOS v12 (Monterey) (Flask or any other).
E.g., use the built-in HTTP server, I cannot get onto port 5000:
python3 -m http.server 5000
... (stack trace)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/socketserver.py", line 466, in server_bind
self.socket.bind(self.server_address)
OSError: [Errno 48] Address already in use
If you have Flask installed and you run the Flask web server, it does not fail on start. Let's take the minimum Flask example code:
# Save as hello.py in the current working directory.
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello_world():
return "<p>Hello, World!</p>"
Then run it (provided you have Flask/Python 3 installed):
export FLASK_APP=hello
flask run
Output:
* Running on http://127.0.0.1:5000/
However, if you try to access this server (from a browser or with anything else), it is denied:
curl -I localhost:5000
HTTP/1.1 403 Forbidden
Content-Length: 0
Server: AirTunes/595.13.1
The process running on this port turns out to be an AirPlay server. You can deactivate it in System Preferences › Sharing and uncheck AirPlay Receiver to release port 5000 .
Mac check port usage from the command line: Simply click on the Network tab and then click on the Ports column to sort by port. You can then scroll through to see which process is using a given TCPIP port number.
This TCP port is opened and used by Universal Plug N' Play (UPnP) devices to accept incoming connections from other UPnP devices. UPnP devices connect to each other using TCP protocol over port 5000.
macOS Monterey introduced AirPlay Receiver running on port 5000. This prevents your web server from serving on port 5000. Receiver already has the port.
You can either:
Turn off AirPlay Receiver
Go to System Preferences → Sharing → Untick Airplay Receiver.
See more details
You should be able to rerun the server now on port 5000 and get a response:
python3 -m http.server 5000
Serving HTTP on :: port 5000 (http://[::]:5000/) ...
Run the server on a different port than 5000
It's probably a better idea to no longer use port 5000 as that's reserved for Airplay Receiver on macOS Monterey.
Just to run the server on a different port. There isn't any need to turn off Airplay Receiver.
python3 -m http.server 4999
or
export FLASK_APP=hello
flask run -p 4999
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With