Solving python macos-monterey OSError: [Errno 48] Address already in use ( localhost:port unavailable )

Python macos-monterey OSError: [Errno 48] Address already in use ( localhost:port unavailable ) is an error which occurs in monterey mostly because of the AirPlay Receiver.

In today’s article I am going to present a set of possible solutions. In order to deal with a confusing error and explain why it takes place.

Exploring python macos-monterey OSError: [Errno 48] Address already in use ( localhost:port unavailable )

This is an error which occurs in monterey mostly because of the AirPlay Receiver.

Beware of mixing between errors. Double check if the error message looks like the error message bellow, then continue.

                                                                       #
OSError: [Errno 48] Address already in use
                                                                       #

I hope one the method bellow will help you solve the problem and get rid of the error for good.

The Method that has solved my problem : Run your web server on a different port or Turn off AirPlay Receiver

This problem usually takes place with port 5000 in Monterey.

When localhost port 5000 is used by another process and you try to access your web server at the same port you will get the error we are trying to solve here.

Even if you do not have an app that uses port 5000 , Monterey already has a problem that triggers the issue.

AirPlay Receiver causes the problem since it by default uses port 5000

There are two possible solutions, either turn off AirPlay Receiver or use a port different than port 5000.

You can run a flask server for example on port 4000

                                                                       #
flask run -p 4000
                                                                       #

or use http.server with python3 and run on port 4000

                                                                       #
python3 -m http.server 4000
                                                                       #

Alternatively, You can also navigate to System Preferences, then navigate to Sharing

After that, navigate to Airplay Receiver and Turn it off

I hope this guide solved your problem, thank you for reading this blog post to the very end.

Summing-up : 

That’s it fellow developers, this is the end of this guide, I hope you found this useful in solving your particular issue, if you have the means and want to help, please support our work on our Kofi account.

Thank you for reading, keep coding and cheers. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/