-1

I am trying to run a flask app on my local machine but in my browsers I get error connection refused messages and sometimes i get the message in my terminal. The app did successfully create my table but I cannot view it in my browser. for host I have tried, localhost, 0.0.0.0 and 127.0.0.1 and for ports I have tried 5000, 8000, 8080, 8002 and I get the same error every time. I do have a VPN installed on my machine but it is turned off and I did a fresh restart without ever running the application and I still get the error. What is going wrong here?

I'm running windows 10 and using a vagrant virtual box running ubuntu 16 uaing gitbash. I have an ipVanish application on my computer for a VPN but the vpn is turned off and I did a fresh restart without opening the application and am still having the problem

This is my code:

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
import os

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://postgres:F00tBall@127.0.0.1:5432/example'
db = SQLAlchemy(app)

class Person(db.Model):
    __tablename__ = 'persons'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(), nullable=False)

db.create_all()

@app.route('/')
def index():
    person = Person.query.first()
    return 'Hello ' + person.name

if __name__ == '__main__':
    app.secret_key = 'super_secret_key'
    app.debug = True
    port = int(os.environ.get('PORT', 5000))
    app.run(host= '127.0.0.1', port=port)

i've also tried

app.run(host='127.0.0.1', port=5000)

i ran `

sudo ufw allow 5000

but that didn't seem to do anything.

What is going wrong here?

2 Answers2

0

If you're running Flask inside of a VM, 'localhost' means local to the VM. Your browser is likely outside the VM, and therefore not local. Instead of 127.0.0.1, use 0.0.0.0

Try it again.

Dave W. Smith
  • 24,318
  • 4
  • 40
  • 46
0

Have you tried using host=0.0.0.0.

I understand this causes flask serve on the IP address address of the machine that is running it. Then connect to that IP address on port 5000?

Configure Flask dev server to be visible across the network

Isd Sava
  • 196
  • 1
  • 7