Flask. Err_Connection_Refused

So I’m trying to learn Flask in Python but when trying to view my work in my browser I keep getting ‘err_connection_refused’… I know this is vague but I’ve tried disabling my firewall as well and making allowances in my firewall for it to work. Also, a couple of Flask related fixes in the code itself but nothing seems to work. I also have this issue outside of codecademy when putting the same code in VScode or PyCharm. Any ideas?

How are you running it? Localserver or are you deploying it somehow?

I think a few more bits of context are necessary for useful feedback. Sharing the code might also be helpful.

So this is the code. It should be pretty much the exact code from one of the earlier Codecademy Introduction to Flask lessons.

Yea the code should be fine. Which goes back to the question of how you are running it. If I’m running it in a local development center, I’ll go to my terminal, go to my app directory, and type something like

export FLASK_APP=myFlaskApp.py
export FLASK_DEBUG=1
flask run

If successful you should get a message like

  • Serving Flask app “main.py” (lazy loading)
  • Environment: production
    WARNING: This is a development server. Do not use it in a production deployment.
    Use a production WSGI server instead.
  • Debug mode: on
  • Running on (Press CTRL+C to quit)
  • Restarting with fsevents reloader
  • Debugger is active!
  • Debugger PIN: 653-345-123

You can then copy and paste the url and paste it into your browser. If you’re getting an error at the point of opening on your browser, try opening on a different browser and see if it’s a browser setting issue first (just in case).