I followed this tutorial for changing the background on my macOS Monterey 12.5. When I run the Python script my background ist not changing but I also don't get an error message.
In System Preferences > Security & Privacy > Automation I added the terminal in which I execute the script for being able to access Finder.
Code to change background:
cmd = "osascript -e 'tell application \"Finder\" to set desktop picture to POSIX file \"" + filename + "\"'"
os.system(cmd)
My problem was that I executed the Python script from iTerm and NOT from the standard Terminal.
Thanks to @Stuart from the comments in the post (how can I link people from comments in answers or should I even do this?).