Azure-Samples / ms-identity-python-flask-webapp-authentication

This sample demonstrates a Python Flask webapp that signs in users in your tenant using Azure Active Directory
MIT License
55 stars 18 forks source link

Import error on running the app #6

Open george-kuanli-peng opened 2 years ago

george-kuanli-peng commented 2 years ago

This issue is for a: (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

  1. install the dependent packages in a virtual environment
    cd <project-root-directory> # the folder into which you cloned the code
    python3 -m venv venv # only required if you don't have a venv already
    source venv/bin/activate
    pip install -r requirements.txt
  2. run the app on Linux
    . .\run.flask.dev.ps1

Any log messages given by the failure

Traceback (most recent call last):
  File "/prac-msgraph/ms-identity-python-flask-webapp-authentication/venv/bin/flask", line 5, in <module>
    from flask.cli import main
  File "/prac-msgraph/ms-identity-python-flask-webapp-authentication/venv/lib/python3.8/site-packages/flask/__init__.py", line 14, in <module>
    from jinja2 import escape
  File "/prac-msgraph/ms-identity-python-flask-webapp-authentication/venv/lib/python3.8/site-packages/jinja2/__init__.py", line 12, in <module>
    from .environment import Environment
  File "/prac-msgraph/ms-identity-python-flask-webapp-authentication/venv/lib/python3.8/site-packages/jinja2/environment.py", line 25, in <module>
    from .defaults import BLOCK_END_STRING
  File "/prac-msgraph/ms-identity-python-flask-webapp-authentication/venv/lib/python3.8/site-packages/jinja2/defaults.py", line 3, in <module>
    from .filters import FILTERS as DEFAULT_FILTERS  # noqa: F401
  File "/prac-msgraph/ms-identity-python-flask-webapp-authentication/venv/lib/python3.8/site-packages/jinja2/filters.py", line 13, in <module>
    from markupsafe import soft_unicode
ImportError: cannot import name 'soft_unicode' from 'markupsafe' (/prac-msgraph/ms-identity-python-flask-webapp-authentication/venv/lib/python3.8/site-packages/markupsafe/__init__.py)

Expected/desired behavior

The app could start succeessfully

OS and Version

Ubuntu Linux 20.04

Mention any other details that might be useful

I found the MarkupSafe package installed is of version 2.1.1. After downgrading it to version 2.0.1 and restart the app, it works!

JeroenvIS commented 1 year ago

I hit the same issue. Indeed, downgrading 'markupsafe' to 2.0.1 seems to solve it. Found this URL where it's also explained why the ImportError occurs with markupsafe >= 2.1.1: the soft_unicode method was already deprecated and was removed in 2.1.1 (also see here).

waldmannly commented 1 year ago

'pip install markupsafe==2.0.1' will fix this for now. Version should be specified in the requirements.txt.