ImportError: cannot import name 'safe_str_cmp' from 'werkzeug.security'

I just updated from stable to the current rc (rc3) from the UI and now octopi won't start. This is the error in the log.

How can I fix or rollback without reimaging octopi?

ImportError: cannot import name 'safe_str_cmp' from 'werkzeug.security' (/home/pi/oprint/lib/python3.7/site-packages/werkzeug/security.py)
2022-03-28 15:32:16,105 - octoprint.plugin.core - INFO - Found 18 plugin(s) providing 16 mixin implementations, 30 hook handlers
2022-03-28 15:32:16,121 - octoprint.cli.server - ERROR - Uncaught exception
Traceback (most recent call last):
  File "/home/pi/oprint/bin/octoprint", line 8, in <module>
    sys.exit(main())
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/__init__.py", line 936, in main
    octo(args=args, prog_name="octoprint", auto_envvar_prefix="OCTOPRINT")
  File "/home/pi/oprint/lib/python3.7/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/pi/oprint/lib/python3.7/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/pi/oprint/lib/python3.7/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/pi/oprint/lib/python3.7/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/pi/oprint/lib/python3.7/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/pi/oprint/lib/python3.7/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/cli/server.py", line 330, in serve_command
    disable_color=no_color,
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/cli/server.py", line 145, in run_server
    from octoprint.server import CannotStartServerException, Server
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/server/__init__.py", line 33, in <module>
    from flask_login import (  # noqa: F401
  File "/home/pi/oprint/lib/python3.7/site-packages/flask_login/__init__.py", line 16, in <module>
    from .login_manager import LoginManager
  File "/home/pi/oprint/lib/python3.7/site-packages/flask_login/login_manager.py", line 24, in <module>
    from .utils import (login_url as make_login_url, _create_identifier,
  File "/home/pi/oprint/lib/python3.7/site-packages/flask_login/utils.py", line 13, in <module>
    from werkzeug.security import safe_str_cmp
ImportError: cannot import name 'safe_str_cmp' from 'werkzeug.security' (/home/pi/oprint/lib/python3.7/site-packages/werkzeug/security.py)

ok, I have fixed this with:

~/oprint/bin/pip install octoprint --force-reinstall --no-cache-dir

2 Likes

I'm surprised you were able to solve this with a reinstall of OctoPrint, as the issue lies with a third party library that saw an update yesterday that removed the function that is being tried to be used here. I'll need to pin to an earlier version.

Same here...
Where is that requirements.txt file..which others on stackoverflow, having similar issues, recommended to change so it pins to 2.0.0 of that ..werkzeug... thing ( seems they are good in creating such havoc by removing functions ).

Harald

rc3 will be pushed out today and that fixes the issue. 1.7.x is not affected because that still depends on flask 1.x which in turn does take care of the werkzeug dependency staying compatible to flask-login. For future versions, I've created a ticket.

Thanks..
Can you provide a wget link or the like for updating without the GUI...which obviously is defunct

Harald

You will just be able to use pip install OctoPrint==1.8.0rc3 once it is published later.

1 Like

Alternatively you can manually fix this for 1.8.0rc2 as well by running

pip install "werkzeug<2.1"

On OctoPi:

~/oprint/bin/pip install "werkzeug<2.1"
1 Like

Thanks, it worked

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.