TobKra96 / music_led_strip_control

Audio visualization for LED strips in real-time with web interface on a raspberry pi.
https://tobkra96.github.io/music_led_strip_control/
MIT License
297 stars 64 forks source link

Unable to start since new install - ImportError: cannot import name 'safe_str_cmp' from 'werkzeug.security'' (/usr/local/lib/python3.9/dist-packages/werkzeug/security.py) #153

Closed beardiebeardie closed 2 years ago

beardiebeardie commented 2 years ago

I did a clean install of Raspberry Pi OS version 11 Bullseye kernel 5.10.103-v7+ and decided to install your lights package version 2.

I installed using:

curl -sSL https://raw.githubusercontent.com/TobKra96/music_led_strip_control/master/setup.sh | sudo bash -s -- -b master

I am getting the following trackback error when running:

sudo python3 main.py
Traceback (most recent call last):
  File "/share/music_led_strip_control/server/main.py", line 15, in <module>
    from libs.webserver.webserver import Webserver
  File "/share/music_led_strip_control/server/libs/webserver/webserver.py", line 1, in <module>
    from libs.webserver.blueprints.authentication_api import authentication_api
  File "/share/music_led_strip_control/server/libs/webserver/blueprints/authentication_api.py", line 1, in <module>
    from libs.webserver.executer import Executer
  File "/share/music_led_strip_control/server/libs/webserver/executer.py", line 1, in <module>
    from libs.webserver.blueprints.authentication_executer import AuthenticationExecuter
  File "/share/music_led_strip_control/server/libs/webserver/blueprints/authentication_executer.py", line 4, in <module>
    from flask_login import LoginManager, UserMixin, login_user, logout_user
  File "/usr/local/lib/python3.9/dist-packages/flask_login/__init__.py", line 16, in <module>
    from .login_manager import LoginManager
  File "/usr/local/lib/python3.9/dist-packages/flask_login/login_manager.py", line 24, in <module>
    from .utils import (login_url as make_login_url, _create_identifier,
  File "/usr/local/lib/python3.9/dist-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'' (/usr/local/lib/python3.9/dist-packages/werkzeug/security.py)

Thank you for any help.

beardiebeardie commented 2 years ago

The error was from the new version of Wekzeug 2.1.0 which removed some code needed for this app to run. I ended up fixing it by downgrading flask and Werkzeug from 2.1.0 to 2.0.3

pip uninstall flask and pip uninstall Werkzeug then pip install flask==2.0.3 - which installed the new version of Werkzeug 2.1.0 again. pip uninstall Werkzeug then pip install Werkzeug==2.0.3

42Willow commented 2 years ago

I got this error too when I reinstalled MLSC. Your solution below fixed the problem for me, thank you!

sudo pip3 uninstall flask ~sudo pip3 uninstall Werkzeug~ (Probably don't need this) sudo pip3 install flask==2.0.3 sudo pip3 uninstall Werkzeug sudo pip3 install Werkzeug==2.0.3

lelonet111 commented 2 years ago

thank you i also have this problem and i can fix it with this

sudo pip3 uninstall flask sudo pip3 uninstall Werkzeug (Probably don't need this) sudo pip3 install flask==2.0.3 sudo pip3 uninstall Werkzeug sudo pip3 install Werkzeug==2.0.3

how can i fix now this??? when i open a terminal and paste folowing step by step then everything works fine!

1.\ cd /share/music_led_strip_control/server

2.\ sudo systemctl stop mlsc

3.\ sudo python3 main.py

then it works fine with musicreactiv. And also in the general settings i can now pick the audio device. but after i close the terminal it wont work. but still work with non music reactive. i am a newbie and can not fix that. but some code that run this steps one after other with 10 sec. delay after boot will fix that!?!? what do you think???

thank you

42Willow commented 2 years ago

That's weird, the music effects work for me after I close the terminal... Did you restart after you set the audio input device?

lelonet111 commented 2 years ago

That's weird, the music effects work for me after I close the terminal... Did you restart after you set the audio input device?

yes, when the pi reboot the mlsc runs becaus when i go to cd /share/music_led_strip_control/server, and run sudo python3 main.py, i recive the eror that mlsc allready runs and that i can stop it with sudo systemctl stop mlsc, just like it should work. but if i paste sudo systemctl stop mlsc and then run sudo python3 main.py it works. i can pick the right soundcard and the neopix runs perfect, when i close the terminal the neopix stops but the non music effects work fine.

thank you for you answer

42Willow commented 2 years ago

I think the python program will stop running when you close the terminal... Why do you need to stop and start MLSC anyway?

lelonet111 commented 2 years ago

I think the python program will stop running when you close the terminal... Why do you need to stop and start MLSC anyway?

because i cant pick any soundcard, the sound reactiv mode does not work without select first audio device. with this steps it works.

lelonet111 commented 2 years ago

I think the python program will stop running when you close the terminal... Why do you need to stop and start MLSC anyway?

so for now i found a way, after reboot go over remote desktop open the terminal, then paste cd /share/music_led_strip_control/server

sudo systemctl stop mlsc

sudo python3 main.py

when i close the remote desktop it still run, but that must be fixed ;-),

i also try to make a .sh on desktop and let that run auto after boot but that dont work verry well, i can see the the audio sources and pick one but the mlsc service dont work than.

but i will still try

Teraskull commented 2 years ago

@lelonet111 What? Of course the script will stop working if you close the terminal, That's why systemd is used.

Just run the service again instead of directly with Python:

sudo systemctl start mlsc
Teraskull commented 2 years ago

Closing issue since Flask_Login has been recently updated to remove the deprecated safe_str_cmp. See changelog. Now it is safe to update the following modules:

pip install -U Flask_Login==0.6.0 flask==2.1.1 werkzeug==2.1.1
lelonet111 commented 2 years ago

so i fix it!

go to crontab -e

in the last row i write

@reboot sleep 10 && sudo systemctl stop mlsc && sleep 5 && sudo systemctl start mlsc

lelonet111 commented 2 years ago

https://www.youtube.com/watch?v=0LkKdmZzovE

Teraskull commented 2 years ago

@lelonet111 That's a very bad idea and you shouldn't do it. I already said it's safe to update the modules. Why are you looking for workarounds?

Systemd is smart enough on its own to boot properly with delays after internet connection is established.

How is sleeping going to help an ImportError anyways?

lelonet111 commented 2 years ago

@Teraskull Teraskull I also tried the following, but it didn't solve my problem

pip install -U Flask_Login==0.6.0 flask==2.1.1 werkzeug==2.1.1

Teraskull commented 2 years ago

@lelonet111 Did you try running with sudo? Pip installs modules differently for a user and root.