Setting werkzeug==0.16.1 in your requirements file fixes it. The issue is with the 1.0.0 version

Answer from PILA on Stack Overflow
🌐
Reddit
reddit.com › r/flask › importerror: cannot import name 'url_decode' from 'werkzeug.urls' - flask web app issue
r/flask on Reddit: ImportError: cannot import name 'url_decode' from 'werkzeug.urls' - Flask Web App Issue
October 16, 2023 -

When i run my code using the run.py file i get this error:

Traceback (most recent call last):
  File "C:\Users\ivar\Desktop\Testing\flask-webchat\run.py", line 1, in <module>
    from app import app, socketio
  File "C:\Users\ivar\Desktop\Testing\flask-webchat\app\__init__.py", line 28, in <module>
    from .models import User
  File "C:\Users\ivar\Desktop\Testing\flask-webchat\app\models.py", line 3, in <module>
    from flask_login import UserMixin
  File "C:\Users\ivar\Desktop\Testing\flask-webchat\venv\Lib\site-packages\flask_login\__init__.py", line 12, in <module>
    from .login_manager import LoginManager
  File "C:\Users\ivar\Desktop\Testing\flask-webchat\venv\Lib\site-packages\flask_login\login_manager.py", line 33, in <module>
    from .utils import _create_identifier
  File "C:\Users\ivar\Desktop\Testing\flask-webchat\venv\Lib\site-packages\flask_login\utils.py", line 14, in <module>
    from werkzeug.urls import url_decode
ImportError: cannot import name 'url_decode' from 'werkzeug.urls' (C:\Users\ivar\Desktop\Testing\flask-webchat\venv\Lib\site-packages\werkzeug\urls.py)

The code & requirements.txt can be looked at or downloaded on github: https://github.com/ivarjt/flask-webchat/tree/feature/login-system

What I have tried so far:

Uninstalling and installing libraries mentioned in the error code.

Thanks in advance for any help!

Edit:

as u/ArabicLawrence said, the problem was that my flask-login version is incompatible with werkzeug.

pip install werkzeug==2.3.0

Discussions

ImportError: cannot import name 'url_encode'
Werkzeug changed the url_encode function from werkzeug.url_encode to werkzeug.urls.url_encode. Current setup results in this error on startup of the web container: Simple fix should be to bump flas... More on github.com
🌐 github.com
6
February 9, 2020
ImportError: cannot import name 'url_decode' from 'werkzeug.urls' -> upgrade Flash-Login to 0.6.3+
After a pip upgrade I am getting (and have been getting in previous upgrades) the following error: ImportError: cannot import name 'url_decode' from 'werkzeug.urls' The reason this ... More on github.com
🌐 github.com
3
May 8, 2024
Getting ImportError: cannot import name 'URL' from 'werkzeug.urls' while installing odoo17.
from werkzeug.urls import URL, url_parse, url_encode, url_quote · ImportError: cannot import name 'URL' from 'werkzeug.urls' (/home/siddharth/py3.12-env/lib/python3.12/site-packages/werkzeug/urls.py) I tried to change versions of Werkzeug library and tried with lower Python versions also. More on odoo.com
🌐 odoo.com
3
0
December 6, 2023
Having troubles running app.py
https://w.trhou.se/unmq8wuhez After ... "/usr/local/lib/python3.9/site-packages/flask_wtf/recaptcha/widgets.py", line 4, in from werkzeug import url_encode ImportError: cannot import name 'url_encode' from 'werkzeug' (/usr/local/lib/python3.9/site-packages/werkzeug/init.... More on teamtreehouse.com
🌐 teamtreehouse.com
1
December 3, 2020
🌐
GitHub
github.com › evilsocket › pwnagotchi › issues › 831
ImportError: cannot import name 'url_encode' from 'werkzeug' · Issue #831 · evilsocket/pwnagotchi
March 5, 2020 - Currently when running commands like pwnagotchi -h it fails with ImportError: cannot import name 'url_encode' from 'werkzeug' error. Seems like Werkzeug deprecated this function in 1.0.0 (released Feb 7, 2020) which is what currently get...
Author   evilsocket
🌐
GitHub
github.com › scoringengine › scoringengine › issues › 670
ImportError: cannot import name 'url_encode' · Issue #670 · scoringengine/scoringengine
February 9, 2020 - Werkzeug changed the url_encode function from werkzeug.url_encode to werkzeug.urls.url_encode. Current setup results in this error on startup of the web container: Simple fix should be to bump flask-wtf to version 0.14.3 as referenced here.
Author   scoringengine
🌐
OpenPLC
openplc.discussion.community › post › cannot-import-name-urldecode-from-werkzeug-urls-pathtoopenplcv3-venvlibpython3-10sitepackageswerkzeugurls-py-12749551
cannot import name 'url_decode' from 'werkzeug.urls' (/path/to/OpenPLC_V3/.venv/lib/python3.10/site-packages/werkzeug/urls.py) - OpenPLC Forum
October 3, 2023 - Thiago, hello, It's me again 🙂 I think You have to know about it So... : cannot import name 'url_decode' from 'werkzeug.urls' (/path/to/OpenPLC_V3/.venv/lib/python3.10/site-packages/werkzeug/urls.py) This is syslog error while starting openplc systemd My version werkzeug 3.0.x, the reason: update/upgrade there are no 'erl_decode' and 'url_encode' functions And solution: 1. pip3 install --force-reinstall -v "werkzeug==2.3" 2. go to /path/to/OpenPLC_V3/.venv/lib/python3.10/site-packages/ and remove or change name of werkzeug dir 3. find location of reinstalled werkzeug (in my case: ~/.local/lib/python3.10/site-packages/werkzeug) 4. cp -r ~/.local/lib/python3.10/site-packages/werkzeug /path/to/OpenPLC_V3/.venv/lib/python3.10/site-packages/werkzeug 5. start openplc.service
🌐
GitHub
github.com › pgadmin-org › pgadmin4 › issues › 7459
ImportError: cannot import name 'url_decode' from 'werkzeug.urls' -> upgrade Flash-Login to 0.6.3+ · Issue #7459 · pgadmin-org/pgadmin4
May 8, 2024 - To fix this Flask-Login needs to be upgraded to 0.6.3 as from then Werkzeug 3.x if supported · pip install git+https://github.com/maxcountryman/flask-login.git helped me but it is version 0.7-dev so maybe you can try first pip install Flask-Login==0.6.3 · source: https://stackoverflow.com/questions/77215107/importerror-cannot-import-name-url-decode-from-werkzeug-urls
Author   pgadmin-org
🌐
IQCode
iqcode.com › code › shell › cannot-import-urlencode-from-werkzeug
cannot import urlencode from werkzeug Code Example
August 27, 2021 - pip install werkzeug==0.16.0 # Use an older version of werkzeug # or let a newer version of werkzeug import from werkzeug.urls
🌐
Odoo
odoo.com › forum › help-1 › getting-importerror-cannot-import-name-url-from-werkzeugurls-while-installing-odoo17-238903
Getting ImportError: cannot import name 'URL' from 'werkzeug.urls' while installing odoo17. | Odoo
December 6, 2023 - Hello! I'm getting import error while installing odoo17 community in my local system. File "/home/siddharth/odoo/odoo/odoo/ http.py [1] ", line 161, in from werkzeug.urls import URL, url_parse, url_encode, url_quote ImportError: cannot import name 'URL' from 'werkzeug.urls' (/home/siddharth/py3.12-env/lib/python3.12/site-packages/werkzeug/ urls.py [2] ) I tried to change versions of Werkzeug library and tried with lower Python versions also.
Find elsewhere
🌐
CSDN
devpress.csdn.net › python › 63045a23c67703293080bac2.html
ImportError: cannot import name 'url_encode' from 'werkzeug'_python_Mangs-Python
August 23, 2022 - Answer a question I am currently running a conda environment with flask-wtf version 0.14.2 and wtforms version 2.21 and I have trouble solving this ImportError: cannot import name 'url_encode' from 'w Mangs Python
🌐
GitHub
github.com › pallets › flask › issues › 3481
Greedy version requirement for werkzeug breaking fresh installs · Issue #3481 · pallets/flask
February 7, 2020 - Any fresh installs/updates to flask as of the last few hours crash with an import error ImportError: cannot import name 'url_encode' from 'werkzeug' (/Users/me/env/lib/python3.7/site-packages/werkzeug/init.py) due to a major version chan...
Author   pallets
🌐
Beautiful Soup
tedboy.github.io › flask › _modules › werkzeug › urls.html
werkzeug.urls — Flask API
""" import os import re from werkzeug._compat import text_type, PY2, to_unicode, \ to_native, implements_to_string, try_coerce_native, \ normalize_string_tuple, make_literal_wrapper, \ fix_tuple_repr from werkzeug._internal import _encode_idna, _decode_idna from werkzeug.datastructures import MultiDict, iter_multi_items from collections import namedtuple # A regular expression for what a valid schema looks like _scheme_re = re.compile(r'^[a-zA-Z0-9+-.]+$') # Characters that are safe in any part of an URL.
🌐
pythontutorials
pythontutorials.net › blog › importerror-cannot-import-name-url-decode-from-werkzeug-urls
How to Fix ImportError: cannot import name 'url_decode' from 'werkzeug.urls' in Flask with flask-login — pythontutorials.net
If you’re working on a Flask application and using `flask-login` for user authentication, you might encounter an error like this: ```bash ImportError: cannot import name 'url_decode' from 'werkzeug.urls' ``` This error is frustrating, but it’s rooted in a common issue: **dependency version conflicts** between `flask-login` and `Werkzeug` (a core dependency of Flask).
🌐
GitHub
github.com › pallets › werkzeug › issues › 2796
loginmanager issue - cannot import name 'url_decode' from 'werkzeug.urls · Issue #2796 · pallets/werkzeug
October 6, 2023 - I have python 3.11 running a venv with flask 3.0 and Werkzeug 3.0. However running from >>>flask_login import LoginManager i get from werkzeug.urls import url_decode ImportError: cannot import name 'url_decode' from 'werkzeug.urls' (/home/erver/venv/lib/python3.11/site-packages/werkzeug/urls.py)
Author   pallets
🌐
GitHub
github.com › microsoftgraph › python-sample-auth › issues › 21
[sample_flask.py] ImportError: Cannot import name from 'werkzeug' · Issue #21 · microsoftgraph/python-sample-auth
February 13, 2020 - from werkzeug.urls import url_quote, url_decode, url_encode from werkzeug.http import parse_options_header from werkzeug.utils import cached_property
Author   microsoftgraph
Top answer
1 of 6
30

I can only assume you got the Werkzeug 3.0 update (as flask-login didn't up-bound their werkzeug dependency).

In their ongoing quest to remove all the non-core public APIs of werkzeug, the developers deprecated most of werkzeug.urls in Werkzeug 2.3 (released April 25th 2023), and removed it in Werkzeug 3.0 (released September 30th 2023).

Your options are:

  • force werkzeug to a pre-3.0 version

  • wait for flask-login to release a version compatible with werkzeug 3, a fix of that and a bunch of other stuff was merged a few minutes ago

    edit: flask-login 0.6.3 with the compatibility fix was released October 30th: https://github.com/maxcountryman/flask-login/releases/tag/0.6.3

2 of 6
9

The problem was as described by @Masklinn. I fixed the problem by changing the versions of werkzeug and flask in my requirements.py and reinstalling them.

My original requirements.txt:

bcrypt==4.0.1
blinker==1.6.2
click==8.1.7
dnspython==2.4.2
email-validator==2.0.0.post2
Flask==3.0.0
Flask-Bcrypt==1.0.1
Flask-Login==0.6.2
Flask-SQLAlchemy==3.1.1
Flask-WTF==1.2.0
greenlet==2.0.2
idna==3.4
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.3
SQLAlchemy==2.0.21
typing_extensions==4.8.0
Werkzeug==3.0.0
WTForms==3.0.1

My modified requirements.txt:

bcrypt==4.0.1
blinker==1.6.2
click==8.1.7
dnspython==2.4.2
email-validator==2.0.0.post2
Flask==2.3.0
Flask-Bcrypt==1.0.1
Flask-Login==0.6.2
Flask-SQLAlchemy==3.1.1
Flask-WTF==1.2.1
greenlet==2.0.2
idna==3.4
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.3
SQLAlchemy==2.0.21
typing_extensions==4.8.0
Werkzeug==2.3.0
WTForms==3.0.1
🌐
GitHub
github.com › maxcountryman › flask-login › issues › 782
cannot import name 'url_decode' from 'werkzeug.urls' (no duplicates!!!) · Issue #782 · maxcountryman/flask-login
October 3, 2023 - After upgrading to Flask 3.0.0, the following imports no longer work in flask_login/utils.py: from werkzeug.urls import url_decode from werkzeug.urls import url_encode To Reproduce Steps to reprodu...
Author   maxcountryman
🌐
Arch Linux
bugs.archlinux.org › task › 65455
FS#65455 : [python-flask-babelex] broken due to python-werkzeug 1.0.0
February 11, 2020 - Unfortunately the error simply ... "/usr/lib/python3.8/site-packages/flask_wtf/recaptcha/widgets.py", line 5, in <module> from werkzeug import url_encode ImportError: cannot import name 'url_encode' from 'werkzeug' (/usr/lib/python3.8/site-packages/werkzeug/__init__.py) Comment ...