Gitpod+Flask: Port Not Found Error in Preview Browser


1 min read

After spending hours trying to figure out why gitpod shows the "Port not found" error page instead of our flask-based application's index page, the diagnosis is:

  1. The root cause of the problem is still unknown.
  2. Most likely this is caused by unexpected behavior of flask as on startup it briefly opens and closes the port and just moments later reopens it again.
  3. I think that the first time flask opens the port, gitpod detects that and opens the preview browser which, unfortunately, sends its request to the port just after flask closed it, which causes the browser to show the error page.
  4. It is possible to use socat (or a similar tool) to fix the issue.
  5. To do so, instruct gitpod to ignore flask's port and open preview on some other port, i.g. 8080.
  6. Start your flask app and then run socat like this: socat TCP-LISTEN:8080,fork TCP4:localhost:5000

socat (SOcket CAT) is a great tool!