Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save HarunMbaabu/3326712e0b15c3053843c771ed444807 to your computer and use it in GitHub Desktop.
Save HarunMbaabu/3326712e0b15c3053843c771ed444807 to your computer and use it in GitHub Desktop.

The error message "OSError: [Errno 98] Address already in use" typically occurs when the port you are trying to use for your Flask application is already being used by another process. By default, Flask uses port 5000.

To resolve this issue, you can try the following solutions:

1). Change the port number: Specify a different port number in your Flask script by modifying the app.run() statement. For example, you can use app.run(port=5001) to run the Flask application on port 5001 instead of the default 5000.

if __name__ == '__main__':
    app.run(port=5001, debug=True

2). Stop the conflicting process: Find the process that is already using the port you want to use (in this case, port 5000) and stop it. This can be done by finding the process ID (PID) and then terminating it. On Unix-based systems, you can use the following command to find the process using port 5000:

sudo lsof -i :5000

The command will display the process using that port along with its PID. You can then terminate it using the kill command followed by the PID:

sudo kill <PID>

After terminating the conflicting process, you should be able to run your Flask application on port 5000 without any issues.

3). Wait for the port to be released: If you recently stopped a Flask application or any other process running on the port, it might take some time for the operating system to release the port. In such cases, you can wait for a few minutes and then try running your Flask application again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment