0

I'm trying to deploy a flask app on a linux server. Currently, I'm testing it I'm try to run it with the following commands.

export FLASK_APP=main.py

flask run --host=0.0.0.0

When I run this and try to navigate to [SERVER IP]:5000, there is a failed connection to the server. I've tried to implement solutions I've found elsewhere such as here:Can't connect to Flask web service, connection refused

I've made these changes and it still does not work:

if __name__ == '__main__':
    app.run(host='0.0.0.0',port=5000)
sudo ufw allow 5000

Some information about the server - Through linode running Ubuntu 21.04

Any help would be greatly appreciated.

3
  • 1
    Can you connect to it locally telnet 127.0.0.1 5000 , (or curl) , if its working then try to find out why external connection not going through, may be firewall issue/ routing issue? Commented Sep 7, 2021 at 22:36
  • It does work locally. Again, I mentioned in the question that I enabled port 5000, so I assumed that that would resolve any firewall issues Commented Sep 7, 2021 at 23:09
  • Are you connect via a proxy ? can you telnet telnet serverip 5000 from another server ? ping from another server to your flask app server ip and check the connectivity. Commented Sep 8, 2021 at 22:29

2 Answers 2

2

You should execute main.py directly if you're using __name__ == "__main__"

if __name__ == '__main__':
    app.run(host='0.0.0.0',port=5000)

Your app.run() call isn't executed when using flask run

It should run on port 5000 by default so there shouldn't be any need for that configuration.

Try python3 main.py as suggest above and share the outcome.

Sign up to request clarification or add additional context in comments.

Comments

1

Can you try to run it as python main.py from the terminal?

or

python3 main.py

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.