I have a very basic flask app with dependencies installed from my requirements.txt. All of these dependencies are installed in my virtual environment.
requirements.txt given below,
aniso8601==6.0.0
Click==7.0
Flask==1.0.3
Flask-Cors==3.0.7
Flask-RESTful==0.3.7
Flask-SQLAlchemy==2.4.0
itsdangerous==1.1.0
Jinja2==2.10.1
MarkupSafe==1.1.1
# psycopg2-binary==2.8.2
pytz==2019.1
six==1.12.0
# SQLAlchemy==1.3.4
Werkzeug==0.15.4
python-dotenv
requests
authlib
My code in NewTest.py file,
from flask import Flask, request, jsonify, abort, url_for
app = Flask(__name__)
@app.route('/')
def index():
return jsonify({
'success': True,
'index': 'Test Pass'
})
if __name__ == '__main__':
app.run(debug=True)
When I run the app through,
export FLASK_APP=NewTest.py
export FLASK_ENV=development
export FLASK_DEBUG=true
flask run
or flask run --reload
I get the following error,
127.0.0.1 - - [09/Feb/2020 12:43:40] "GET / HTTP/1.1" 500 -
Traceback (most recent call last):
File "/projects/env/lib/python3.8/site-packages/flask/_compat.py", line 36, i
n reraise
raise value
File "/projects/NewTest.py", line 3, in <module>
app = Flask(__name__)
File "/projects/env/lib/python3.8/site-packages/flask/app.py", line 559, in _
_init__
self.add_url_rule(
File "/projects/env/lib/python3.8/site-packages/flask/app.py", line 67, in wr
apper_func
return f(self, *args, **kwargs)
File "/projects/env/lib/python3.8/site-packages/flask/app.py", line 1217, in
add_url_rule
self.url_map.add(rule)
File "/projects/env/lib/python3.8/site-packages/werkzeug/routing.py", line 1388, in add
rule.bind(self)
File "/projects/env/lib/python3.8/site-packages/werkzeug/routing.py", line 730, in bind
self.compile()
File "/projects/env/lib/python3.8/site-packages/werkzeug/routing.py", line 794, in compile
self._build = self._compile_builder(False).__get__(self, None)
File "/projects/env/lib/python3.8/site-packages/werkzeug/routing.py", line 951, in _compile_builder
code = compile(module, "<werkzeug routing>", "exec")
TypeError: required field "type_ignores" missing from Module
Can anyone please point out what am I missing or doing wrong and how can I fix it? Thanks.
try
pip uninstall Flask
then
pip install Flask
and
pip uninstall Werkzeug
then
pip install Werkzeug
werkzeug library can have issues with different python versions.
First of all, upgrade the werkzeug library to be the latest, then try again.
pip3 install --upgrade werkzeug
If that didn't work, I presume you may be using python version which kind of creates the whole issue.
You can always create a virtualenv [Install, Create, and Activate] with a specific python version where werkzeug won't cause you this issue.
I solved the error by simply executing the following line of code on the terminal:
sudo pip3 install --upgrade ipython
The bug was fixed in werkzeug 0.15.5. Upgrade from 0.15.4 to to a later version.