Forums

"address already in use " problem

Hi, I deployed an Flask app to pythonanywhere, but I am not able to kill the process even I have remove the whole app and create new one.

Whenever I want to start the python script, it shows that "Address already in use".

Please suggest how do I solve this issue?

You probably have an app.run call in your flask app. That doesn't work on PythonAnywhere. You need to use the WSGI wrapper and create a web app for it to work. There's some discussion here where we help someone else with the same issue.

Hi, i removed the app run code from the flask_app.py (my main script), and copy it to the WSGI py.

and reload the app. the web page is still showing Error code: 502-backend

did i miss anything?

import sys

project_home = u'/home/wujiayi47/mysite'

if project_home not in sys.path:

sys.path = [project_home] + sys.path

from flask_app import app as application

application.run()

Thanks, it is working now somehow.. :)

Don't use application.run(). Ever. It will break your app.

Ahem. that was a bit terse. I should explain. Our infrastructure has web workers that will server any WSGI app for you. They find them by looking for a python variable called application inside your WSGI file.

Flask's application.run() tries to start its own WSGI server, which breaks when it's run inside our web workers. That's why you were seeing the 502-backed errors.

So just the line

from flask_app import app as application

is enough.

IT DOESNT WORK!

What doesn't work, exactly? This forum thread is from three years ago.

Hi,

When I try to connect through DBeaver (version 23.1.3), it raises an error, saying that address already in use. I attached the error here. Does anyone has an idea about how to solve it?

https://prnt.sc/dmaJL2L4OVlO

Thank you.

Have you seen the DBeaver section of this help page? - https://help.pythonanywhere.com/pages/AccessingMySQLFromOutsidePythonAnywhere/

The page gave the solution! Thank you!