Forums

Python Flask [Errno 98] Address already in use

Hi,

I am trying to launch a flask app, but I have the following error message :

Traceback (most recent call last):
  File "/home/moibnj/flask_2017/flask_app.py", line 136, in <module>
    app.run(debug=True)
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 843, in run
    run_simple(host, port, self, **options)
  File "/usr/local/lib/python3.5/dist-packages/werkzeug/serving.py", line 677, in run_simple
    s.bind((hostname, port))
**OSError: [Errno 98] Address already in use**

Thank you for you help

Because you're using app.run. See the docs here and here

I used app.run with the recommended way :

if __name__ == '__main__':
app.run()

but I heave the error mentioned above

Are you trying to run a Flask app in a console? Don't do that. It won't work. Our console servers are not able to server web applications. That's what we have the web apps tab for.

In fact on the web, I have a Something went wrong :-( page, that is why I am trying to debug on the console.

The error that is causing that page will be shown in your error log.

I am also having the same problem, but there are no errors listed in my error log. I get this same socket error when I run my app in the console, I am also using app.run in the recommended way, and I also get the "Something went wrong :-(" page. Did you ever figure out a solution?

You can't run your app in the console. That's what web apps are for. If you get a "Something went wrong" page, you'll either have an exception in your error log or in your server log (unless your app messes with logging in some way and prevents the message from getting to the log)

[edited by admin for formatting]

from flask import Flask
import MySQLdb
app = Flask(__name__)

@app.route('/')
def homepage():
    conn=MySQLdb.connect(host="********************************",
                         user="*********",
                         passwd="******",
                         db="*********")
    c=conn.cursor()
    return "hello"


if __name__=="__main__":
    app.run()

this code gives this error :

Traceback (most recent call last):
  File "/home/hackathon/hostel/__init__.py", line 16, in <module>
    app.run()
  File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 841, in run
    run_simple(host, port, self, **options)
  File "/usr/local/lib/python3.6/dist-packages/werkzeug/serving.py", line 708, in run_simple
    inner()
  File "/usr/local/lib/python3.6/dist-packages/werkzeug/serving.py", line 670, in inner
    fd=fd)
  File "/usr/local/lib/python3.6/dist-packages/werkzeug/serving.py", line 564, in make_server
    passthrough_errors, ssl_context, fd=fd)
  File "/usr/local/lib/python3.6/dist-packages/werkzeug/serving.py", line 476, in __init__
    HTTPServer.__init__(self, (host, int(port)), handler)
  File "/usr/lib/python3.6/socketserver.py", line 453, in __init__
    self.server_bind()
  File "/usr/lib/python3.6/http/server.py", line 136, in server_bind
    socketserver.TCPServer.server_bind(self)
  File "/usr/lib/python3.6/socketserver.py", line 467, in server_bind
    self.socket.bind(self.server_address)
OSError: [Errno 98] Address already in use

how to solve?

Hi there, these two guides should help?

http://help.pythonanywhere.com/pages/Flask

https://blog.pythonanywhere.com/121/

No , still getting same error.

You will generally get that error. Those pages where to explain what's happening and what you should do instead.

Okay..thanks