I have been trying to trigger a PAPERLESS_PRE_CONSUME_SCRIPT that I got from this site: https://piep.tech/posts/automatic-password-removal-in-paperless-ngx/.
I have tried to add a scripts folder to my array share, and added the password txt file and the .py script. The script looks like this:
#!/usr/bin/env python
import pikepdf
import os
def unlock_pdf(file_path):
password = None
print("reading passwords")
with open("/usr/src/paperless/scripts/passwords.txt", "r") as f:
passwords = f.readlines()
for p in passwords:
password = p.strip()
try:
with pikepdf.open(file_path, password=password, allow_overwriting_input=True) as pdf:
print("password is working:" + password)
pdf.save(file_path)
break
except pikepdf.PasswordError:
print("password isn't working:" + password)
continue
if password is None:
print("Empty password file")
file_path = os.environ.get('DOCUMENT_WORKING_PATH')
unlock_pdf(file_path)
I have set a path to give the container access to the scripts folder:
And I have set the PAPERLESS_PRE_CONSUME_SCRIPT as a variable to run the script, I just have removed it now since it doesn't work...
I am getting a permission denied error in the logs:
[2023-09-18 23:47:43,698] [ERROR] [paperless.consumer] Error while executing pre-consume script: [Errno 13] Permission denied: '/usr/src/paperless/scripts/removepassword.py'
At one point, I got these messages from the logs.
[2023-09-18 23:02:34,261] [WARNING] [paperless.consumer] Script stderr:
[2023-09-18 23:02:34,263] [WARNING] [paperless.consumer] /usr/bin/env: ‘python\r’: No such file or directory
[2023-09-18 23:02:34,266] [WARNING] [paperless.consumer] /usr/bin/env: use -[v]S to pass options in shebang lines
[2023-09-18 23:02:34,273] [ERROR] [paperless.consumer] Error while executing pre-consume script: Command '['/usr/src/paperless/scripts/removepassword.py', '/tmp/paperless/tmpl40jims_/loennslipp.pdf']' returned non-zero exit status 127.
Does anyone have an idea to what I might be doing wrong? Is there something wrong with the script?