Why won’t my Flask application run?

3 min read

Flask is a lightweight, popular Python framework that lets you quickly build web applications. A lot of Nylas Python examples use Flask (to get started with Nylas, go here). By default, many Flask applications run on port 5000. Best practice when creating a Flask application is to use this port, so why is it the case sometimes that you can’t get it running? What options are available for running on different ports and using different addresses? Let’s find out!

When you’re already using a specific port for a Flask application

If you are already running an application on Flask’s default port 5000, you will get errors trying to start another application. This is because you can’t run two applications on the same port at the same time.

If this is your situation, then you can either stop the application that’s running and start the one you want to run, or change the port and run a second application on the newly selected port. If you want to set a different port from the terminal, you can use this command on a Mac:

$ flask run -h localhost -p 3000

If you want to see what you can do with the Flask commands, at the command line type:

$ flask --help

Airplay Receiver and Flask applications

One of the most common problems using Flask if you have a Mac that’s got Monterey on it or later, is that the Airplay Receiver now uses port 5000. Your Flask app will start up, but it will only start on If you try to go to localhost:5000, you’ll get an error message saying you’re not authorized to look at the page.

To correct this issue with your Flask application, shut off Airplay Receiver. To do this, follow these instructions: How to turn off AirPlay screen sharing on your iPhone, iPad, or Mac computer.

Run your application with

There are many ways to run your Flask application.  If you’re having trouble accessing your application, you might want to try the option. This makes your application accessible by network IP address so another machine in the same network can access it. The method for that is:

 $ if __name__ == "__main__":

NOTE: You cannot access your app from another network. 

Run with

From within your application, you can also choose a specific 127 address to run from as well as changing the port. Here is an example:

$ if __name__ == "__main__":
    app.run(host="", port=8080, debug=True)


Hopefully this post helped you with your Flask application. If you want to integrate email, calendars, and contacts into your Flask application, sign up for a trial with Nylas!

What’s Next?

You can sign up Nylas for free and start building!

Don’t miss the action, watch our LiveStream Coding with Nylas:

Related resources

How to create and read Google Webhooks using Ruby

Create and read your Google webhooks using Ruby and Sinatra, and publish them using Koyeb. Here’s the full guide.

Build mail merge and email templates using TinyMCE Rich Text Editor

Learn how to build Mail Merge and Email Template functionality in your email workflow using TinyMCE Rich Text Editor.

Send emails using TinyMCE Rich Text Editor

Learn how to improve your email workflow using TinyMCE Rich Text Editor.