Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
localhost / 127.0.0.1 took too long to respond - Attempting to run Flask App

I am trying to run a Flask App locally and running into connection to localhost refused issues. My app directory structure looks something like this:

Directory

- index.py
- app.py
auth
-- init.py 

Contents of `init.py` 

from flask import Flask,redirect
from werkzeug.middleware.dispatcher import DispatcherMiddleware
from werkzeug.serving import run_simple
from index import application as dashApp

@server_auth.route('/dashboard')
@login_required
def dashboard():
    return redirect('/dashboard')

app = DispatcherMiddleware(server_auth,
                           {'/dashboard': dashApp.server})

# Change to port 80 to match the instance for AWS EB Environment
if __name__ == '__main__':
    run_simple('0.0.0.0', 80, app, use_reloader=True, use_debugger=True)

I launch the App using gunicorn auth:app command.

[2022-02-11 20:57:24 -0800] [2273] [INFO] Starting gunicorn 20.1.0
[2022-02-11 20:57:24 -0800] [2273] [INFO] Listening at: http://127.0.0.1:8000 (2273)
[2022-02-11 20:57:24 -0800] [2273] [INFO] Using worker: sync
[2022-02-11 20:57:24 -0800] [2274] [INFO] Booting worker with pid: 2274

I have tried a few things to troubleshoot the issue.

netstat -avn | grep 8000
tcp4       0      0  127.0.0.1.8000         *.*                    LISTEN      131072 131072   2273      0 0x0100 0x00000006

Turned off the firewall, flushed dns cache, clear browser cache as mentioned in this link:

https://www.hostinger.com/tutorials/localhost-refused-to-connect-error

over 4 years ago · Santiago Trujillo
4 answers
Answer question

0

with limited info given, I suggest you can try a few other things:

  1. create a simple / get API(without any decorator) and try to hit it with breakpoint() in code to check.
  2. Instead of gunicorn , first try to run with a normal server
python init.py
over 4 years ago · Santiago Trujillo Report

0

If the other answer by @Vismay doesn't work try changing your port from 80 to 8080. Since you didn't provide minimum info, Port 80 might be in use by other services

over 4 years ago · Santiago Trujillo Report

0

Could you try run lsof -i:80 and lsof -i:8000 to determine if they are used.

over 4 years ago · Santiago Trujillo Report

0

Maybe your problem is related to "# Change to port 80 to match the instance for AWS EB Environment". Assuming that you're trying to run it locally, consider that in Linux "You need root to run at port 80" (i.e. use sudo to run your server) while in Windows usually ports under 1024 are considered privileged ports and might need a similar solution. How to fix? Try using a different port for your Flask app (say, 5000).

In other case, it seems that Elastic Beanstalk only uses port 80 for inbound traffic (connection with other instances), so maybe you should try to use a different port. For example, in this part of the EB docs they just use port 8000. This seems to be the same conclusion reached in another SO question: Running Flask port 80 on Elastic-Beanstalk Worker

The ELB worker is connected to an SQS queue, by a daemon that listens to that queue, and (internally) posts any messages to http://localhost:80. Apache is listening on port 80. (...) So the solution I found, is to change which port the local daemon posts to - by reconfiguring it via a YAML config-file, it will post to port 5001, where my Flask app was running. This mean Apache can continue to handle the health-checks on port 80, and Flask can handle the SQS messages from the daemon.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!