Jarda
Jarda

Reputation: 89

Flask demo application not working

I wanted to try an Flask minimal application.

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'

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

It is working ok. If I add app.debug = True before run(), it does not work.

Error is:

Traceback (most recent call last):
  File "app.py", line 10, in <module>
    app.run()
  File "C:\Python34\lib\site-packages\flask\app.py", line 772, in run
    run_simple(host, port, self, **options)
  File "C:\Python34\lib\site-packages\werkzeug\serving.py", line 666, in run_simple
    os.set_inheritable(s.fileno(), True)
OSError: [Errno 9] Bad file descriptor

I used Python 3.4.3, Flask 0.10.1, Werkzeug 0.11.1 and Windows 10. The behavior with or without virtualenv is the same.

Upvotes: 2

Views: 1106

Answers (1)

Frito
Frito

Reputation: 1443

I ran into this same issue on Windows 7 with Python 3.4.2. I ended up having to downgrade Werkzeug from version 0.11.1 to 0.10.4. Full disclosure, I'm not a Python developer by trade since I write .NET in my day-to-day job and am lerning Python so I can't fully explain the reasoning here. Also, I just picked a version by going to Pypi and serching "Werkzeug". If you were not aware, pypi.python.org is the source for your pip installs ;-).

To accomplish that I ended up uninstalling Werkzeug then re-installing it by specifying the version in pip. This worked for me in both my global environment as well as my "virtualenv" in my project.

pip uninstall Werkzeug
pip install Werkzeug==0.10.4

EDIT

Here's the contents of my requirements.txt file. You can uninstall all the different packages you've already installed and install these specific versions by running the command pip install -r requirements.txt, assuming your working directory is where requirements.txt is located and your virtualenv is currently active. In Windows you can use relative paths if needed :-).

itsdangerous==0.24
Werkzeug==0.10.4
WTForms==2.0.2
SQLAlchemy==1.0.9
MarkupSafe==0.23
Jinja2==2.8
Flask==0.10.1
Flask-SQLAlchemy==2.1
Flask-WTF==0.10

Upvotes: 2

Related Questions