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

Answer from Masklinn on Stack Overflow
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
🌐
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

python - ImportError: cannot import name 'url_encode' from 'werkzeug' - Stack Overflow
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 'werkzeug' The More on stackoverflow.com
🌐 stackoverflow.com
loginmanager issue - cannot import name 'url_decode' from 'werkzeug.urls
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) More on github.com
🌐 github.com
2
October 6, 2023
cannot import name 'url_decode' from 'werkzeug.urls' (no duplicates!!!)
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... More on github.com
🌐 github.com
4
October 3, 2023
python - Cannot import name 'url_decode' from 'werkzeug.urls' - Stack Overflow
(.venv) PS C:\Users\HP\Desktop\Projects\Python Based\Web Framework\Flask\LoginPage> flask run --debug Usage: flask run [OPTIONS] Try 'flask run --help' for help. Error: While importing 'app', an More on stackoverflow.com
🌐 stackoverflow.com
🌐
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
🌐
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
🌐
Miguel Grinberg
blog.miguelgrinberg.com › post › we-have-to-talk-about-flask
We Have To Talk About Flask - miguelgrinberg.com
In release 1.0.0 (February 2020), the function was relocated and the import changed to from werkzeug.urls import url_decode
🌐
Ubuntu
bugs.launchpad.net › bugs › 2048769
Bug #2048769 “Adopt to new python-werkzeug 3.0 API” : Bugs : python-werkzeug package : Ubuntu
Python-werkzeug 3.0 was syncronized from Debian experimental. The 3.x track is not API compatible with the 2.x track: https://werkzeug.palletsprojects.com/en/3.0.x/urls/ https://werkzeug.palletsprojects.com/en/2.3.x/urls/ Especially the werkzeug.urls.url_decode method is gone, which leads to import failures like this: ==================================== ERRORS ==================================== _____________ ERROR collecting tests/consumer/storage/test_sqla.py _____________ ImportError ...
🌐
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).
Find elsewhere
🌐
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 › 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
🌐
HatchJS
hatchjs.com › home › 5 ways to fix the `cannot import name ‘url_decode’ from ‘werkzeug.urls’` error
5 Ways to Fix the `cannot import name 'url_decode' from 'werkzeug.urls'` Error
January 5, 2024 - The error “cannot import name ‘url_decode’ from ‘werkzeug.urls'” can also be caused by incorrect import statements. Make sure that you are importing the `url_decode` function from the `werkzeug.urls` module.
🌐
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.
🌐
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 - [sample_flask.py] ImportError: Cannot import name from 'werkzeug'#21 · Copy link · glarcina · opened · on Feb 13, 2020 · Issue body actions · This occurred on Python 3.6 and 3.7. Looks like flask_oauthlib has been deprecated and has changed to authlib so no point reporting this issue on that repo. However, I resolved this error by including the specific modules in \Python3x\Lib\site-packages\flask_oauthlib\client.py: 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
🌐
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
🌐
GitHub
github.com › janeczku › calibre-web › issues › 2904
Werkzeug update to 3.0.0 breaks master branch builds · Issue #2904 · janeczku/calibre-web
October 3, 2023 - Traceback (most recent call last): File "/app/calibre-web/cps.py", line 28, in <module> from cps.main import main File "/app/calibre-web/cps/__init__.py", line 29, in <module> from .MyLoginManager import MyLoginManager File "/app/calibre-web/cps/MyLoginManager.py", line 24, in <module> from flask_login import LoginManager, confirm_login File "/usr/local/lib/python3.10/dist-packages/flask_login/__init__.py", line 12, in <module> from .login_manager import LoginManager File "/usr/local/lib/python3.10/dist-packages/flask_login/login_manager.py", line 33, in <module> from .utils import _create_identifier File "/usr/local/lib/python3.10/dist-packages/flask_login/utils.py", line 14, in <module> from werkzeug.urls import url_decode ImportError: cannot import name 'url_decode' from 'werkzeug.urls' (/usr/local/lib/python3.10/dist-packages/werkzeug/urls.py)
Author   janeczku
🌐
YouTube
youtube.com › sophía wagner
ImportError: cannot import name 'url_decode' from 'werkzeug.urls' - YouTube
ImportError: cannot import name 'url_decode' from 'werkzeug.urls' Hey guys! Hopefully you found a solution that helped you! The Content is licensed under (ht...
Published   February 9, 2024
Views   39
🌐
GitHub
github.com › Novartis › cellxgene-gateway › issues › 87
ImportError: cannot import name 'url_decode_stream' from 'werkzeug.urls' · Issue #87 · Novartis/cellxgene-gateway
January 26, 2024 - I installed cellxgene-gateway using anaconda Python 3.11.5. cellxgene-gateway does not start with error: ImportError: cannot import name 'url_decode_stream' from 'werkzeug.urls' (/home/user/.cellxgene-gateway/lib/python3.11/site-packages...
Author   Novartis
🌐
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 › lss233 › kirara-ai › issues › 1232
[BUG] cannot import name 'url_decode' from 'werkzeug.urls' · Issue #1232 · lss233/kirara-ai
October 19, 2023 - 2023-10-19 10:23:10.685 | ERROR | utils.exithooks:foo:35 - 看样子程序似乎没有正常退出。 2023-10-19 10:23:10.685 | ERROR | utils.exithooks:foo:36 - cannot import name 'url_deco de' from 'werkzeug.urls' (/root/chatgpt/myvenv/lib/python3.11/site-packages/werkzeug/urls. py) NoneType: None 2023-10-19 10:23:10.685 | ERROR | utils.exithooks:foo:37 - 你可以在这里阅读常见问题的解 决方案: 2023-10-19 10:23:10.685 | ERROR | utils.exithooks:foo:38 - https://github.com/lss233/ch atgpt-mirai-qq-bot/issues/85 Exception ignored in atexit callback: <function foo at 0x730df68400>
Author   lss233