Chedim
Down from the metal, up through the cloud and back to the UX

Down from the metal, up through the cloud and back to the UX

Gitpod+Flask: Port Not Found Error in Preview Browser

Chedim's photo
Chedim

Published on Jul 14, 2021

1 min read

Subscribe to my newsletter and never miss my upcoming articles

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!

 
Share this