pythonflask

Import error on Flask CRUD App from import Modus from and url_decode


I am trying to develop a CRUD app using flask. The API is a simple REST API using add, update, delete and show.

from flask import Flask, render_template, redirect, url_for, request
from flask_modus import Modus
from toy import Toy
...

The update on the route need to use a flask_modus and import Modus since I need to use request method using b"PATCH". I installed the flask-modus package using pip install flask-modus command. Error: While importing 'app', an Import Error was raised:

When I run the app using flask run I ran into a problem on line 2 and line 3 . Line 2 is complaining about Import Error and (Line 3 in is about import error too about url_decode. ImportError: cannot import name 'url_decode' from 'werkzeug' (/usr/local/lib/python3.10/dist-packages/werkzeug/__init__.py)

__ flask run
Usage: flask run [OPTIONS]
Try 'flask run --help' for help.

Error: While importing 'app', an ImportError was raised:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/flask/cli.py", line 245, in locate_app
    __import__(module_name)
  File "/root/python3-funda/flask-crud/app.py", line 2, in <module>
    from flask_modus import Modus
  File "/usr/local/lib/python3.10/dist-packages/flask_modus.py", line 3, in <module>
    from werkzeug import url_decode
ImportError: cannot import name 'url_decode' from 'werkzeug' (/usr/local/lib/python3.10/dist-packages/werkzeug/__init__.py)

On Google the wekzeug package for functions like (url_decode, url_quote and URL) were deprecated in Werkzeug versions 2.3 and later, and subsequently removed entirely in Werkzeug 3.0.0.


Solution

  • There's likely version mismatch here between flask and werkzeug. Try downgrading with pip install Werkzeug==2.2.2