OSError: [Errno 98] Address already in use Running Flask Application on Apache2 OSError: [Errno 98] Address already in use Running Flask Application on Apache2 flask flask

OSError: [Errno 98] Address already in use Running Flask Application on Apache2


Two things come to mind when I see this.

  1. Do you have Apache installed and running on the server? Apache may be listening on port 80 and preventing your Python script from binding to that port, but the way you ran netcat won't show this. You can check this at [sever_ip]:80.

    But as you can see my ports are empty and not being used. I check that using the command netstat -ntlp

Note the first line of output from that command: (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) Apache runs with elevated privileges, so you'll need to run as root (append sudo to the beginning of your command) to see its port binding. I'd bet that this is the issue. Once this is fixed, you may run in to the following issue:

  1. Are you running the script as root? On Linux, you need to use sudo to bind to ports 0 through 1024 (as explained here).

One more thing, not related to the script specifically, but it looks like you're using AWS EC2 in the screenshots (correct me if I'm wrong). If you want to be able to reach the instance on port 80 from the public internet, you'll need to make sure you allow it in the Security Group. I know this can cause some confusion for people using AWS EC2 for the first time, sure did for me.

Hope this helps!