I have Flask==1.0.2, Jinja2>=2.10.1 which is dockerized, I am getting below error
File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/local/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
return self.load_wsgiapp()
File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python3.7/site-packages/gunicorn/util.py", line 359, in import_app
mod = importlib.import_module(module)
File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/app/search_service/__init__.py", line 12, in <module>
from flasgger import Swagger
File "/usr/local/lib/python3.7/site-packages/flasgger/__init__.py", line 10, in <module>
from .base import Swagger, Flasgger, NO_SANITIZER, BR_SANITIZER, MK_SANITIZER, LazyJSONEncoder # noqa
File "/usr/local/lib/python3.7/site-packages/flasgger/base.py", line 19, in <module>
from flask import Blueprint
File "/usr/local/lib/python3.7/site-packages/flask/__init__.py", line 19, in <module>
from jinja2 import Markup, escape
ImportError: cannot import name 'Markup' from 'jinja2' (/usr/local/lib/python3.7/site-packages/jinja2/__init__.py)
Requirements.txt
attrs>=19.1.0
boto3==1.17.23
click==7.0
itsdangerous==2.0.1
flasgger==0.9.5
Flask==1.0.2
Flask-RESTful>=0.3.6
flask-cors==3.0.8
gunicorn==20.1.0
Jinja2>=2.10.1
jsonschema>=3.0.1,<4.0
marshmallow>=3.0,<=3.6
marshmallow3-annotations>=1.0.0
pytz==2021.1
requests>=2.25.0
requests-aws4auth==1.1.0
statsd==3.2.1
typing==3.6.4
werkzeug>=2.0.0
wheel==0.36.2
itsdangerous==2.0.1
Dockerfile
FROM python:3.7-slim
WORKDIR /app
COPY ./search/ /app/
COPY requirements.txt /app/requirements.txt
RUN pip3 install --trusted-host pypi.org --trusted-host files.pythonhosted.org --default-timeout=100 -e .
RUN pip3 uninstall jinja2 --yes
RUN pip3 install --trusted-host pypi.org --trusted-host files.pythonhosted.org --default-timeout=100 --upgrade jinja2
It was running fine till yesterday, I started getting this error from today, Tried updating the jinja2
but didn't solve the issue, Please help me resolve this.
Thanks in advance!
CodePudding user response:
Version 3.0.1
Regarding to the documentation
Fixed calling deprecated jinja2.Markup without an argument. Use markupsafe.Markup instead. #1438
So to import Markup use the following code :
>>> from jinja2.utils import markupsafe
>>> markupsafe.Markup()
Markup('')
CodePudding user response:
The actual version of jinja is 3.x try to update jinja:
- Uninstall Jinja2==2.10.1
pip uninstall jinja2
- Install the latest version of jinja2
pip install --upgrade jinja2
CodePudding user response:
As the import error comes from flask File "/usr/local/lib/python3.7/site-packages/flask/__init__.py
I tried to create a new Flask application using Flask==1.0.2
and found that the error comes from this version of Flask when it used with Jinja2>=2.10.1.
But when you remove Flask==1.0.2
and install Flask==2.0.3
, everything works fine.
pip uninstall Flask Jinja2
pip install Flask Jinja2
Dependencies
pip freeze
click==8.0.4
Flask==2.0.3
itsdangerous==2.1.2
Jinja2==3.1.1
MarkupSafe==2.1.1
Werkzeug==2.0.3