-1

Hi when I try running my flask app on python anywhere it keeps bringing up this error:

Traceback (most recent call last):
  File "/home/Yaseen/mysite/flask_app.py", line 395, in <module>
    app.run(debug=True)
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 920, in run
    run_simple(t.cast(str, host), port, self, **options)
  File "/usr/local/lib/python3.10/site-packages/werkzeug/serving.py", line 1083, in run_simple
    run_with_reloader(
  File "/usr/local/lib/python3.10/site-packages/werkzeug/_reloader.py", line 444, in run_with_reloader
    sys.exit(reloader.restart_with_reloader())
SystemExit: 0

I went to the code segment it was referring to but I don't understand why its pointing to that segment. On my local machine this error does not come up. Any idea of what it is and how to fix it?

Below is the line of code that is referenced in the console?

app.run(debug=True)

EDIT 1:

app = Flask(__name__)

cors = CORS(app)

the above snippet is found at the beginning of the flask file.

# links the required files for the app
if __name__ == "__main__":
    app.run(debug=True)
    url_for('static', filename='static\js\SignUp.js')
    url_for('static', filename='static\js\Login.js')
    url_for('static', filename='static\js\menu.js')
    url_for('static', filename='static\js\index.js')
    url_for('static', filename='static\css\style.css')
    url_for('static', filename='static\images\LOGO (2).jpg')
    url_for('static', filename='static\images\logoo.jpg')
    url_for('static', filename='static\images\Logo2.jpg')
    url_for('static', filename='static\images\services.jpg')
    url_for('static', filename='static\images\contactUs.jpg')
    url_for('static', filename='static\images\instagram.jpg')
    url_for('static', filename='static\images\facebook.jpg')
    url_for('static', filename='static\images\tiktok.jpg')
    url_for('static', filename='static\images\twitter.jpg')
# links the required files for the app

as requested the lines before and I decided to add the lines after the referenced line of code.

  • Hi! Could you share more information about your server itself? I.e. the lines above the `app.run(...)` that you shared. As-is the code cannot be used to reproduce the issue. – Andrew F Jan 18 '23 at 08:57
  • I added the line before the app.run and also the lines after. – Yaseen Latiff Jan 18 '23 at 09:00
  • Thanks for the edit, but this still doesn't give enough information to reproduce the issue. How do you define `app = ...` and what routes do you attach to it? Based on the traceback my guess would be that something about how the server is configured is preventing it from staying alive, so the reloader keeps killing the process. That can't be confirmed without more info about the server configuration. – Andrew F Jan 18 '23 at 09:01
  • app = Flask(__name__) cors = CORS(app) – Yaseen Latiff Jan 18 '23 at 09:07
  • That is more or less I cna think of in terms of the configuration – Yaseen Latiff Jan 18 '23 at 09:07

1 Answers1

0

This issue appears to be specifically related to the environment provided by PythonAnywhere. According to their docs, you should not use `app.run(...). In particular:

When you're using Flask on your own PC, you'll often "run" flask using a line that looks something like this:

app.run(host='127.0.0.1',port=8000,debug=True)

That won't work on PythonAnywhere -- the only way your app will appear on the public internet is if it's configured via the web tab, with a wsgi file.

While the code snippet you shared indeed wraps the app.run(...) call within an if __name__ == "__main__": ... block, the error you shared suggests that an app.run(..) is still being called. On line 395 in particular.

PythonAnywhere provides a comprehensive tutorial on setting up a Flask application here. In particular, it is important for your flask_app.py file to define an app = Flask(...) but for the wsgi configuration to point to it.

Andrew F
  • 2,690
  • 1
  • 14
  • 25