502 Bad Gateway with Flask Webapp

Hi there!

I tried to move my Flask webapp, which works fine with the builtin debug webserver on my local machine, to PythonAnywhere. Now, all I get is a 502 response. The logs don't change when I restart or reach the website. Any pointers as to what could be the problem?

I'm quite sure it's a problem with my code, but without any other error messages I'm helpless :S

Edit: […]

My webapp is structured as a package as described in the flask documentation like this:



Edit2: Deleted parts of the last edit with observations which had nothing to do with the problem to facilitate future searches.

Any help appreciated!

Hi ktmood,

Looking through our logs I can see the problem. You are doing an somewhere in your code. You don't need to do that. That starts the flask testserver. You just need to import app into your file. Which you are already doing or we wouldn't be seeing the errors in our logs.

What's happening here is our web server is loading your app. It is forking and trying to start a webserver. It's failing. A response is never even sent through to our server so it looks like a bad gateway (which it is) and nothing is logged.

A basic flask web app just looks like this

from flask import Flask

app = Flask(__name__)

def root_view():
return "Hello, World")

And then that app instance is imported into the relevant file and run by our servers.

So there is an errant which you would only do in a testing environment. Not in production. But yes! An impossible problem for you to debug from your end. Something we should probably fix.

I forgot about that one :S

Thank you very much for solving my problem! I feel great right now. Thanks! :)

PythonAnywhere really is awesome!

No problem, and we love the little dedication at the bottom of Thank you :)