Home > Net >  Default permissions for files that are automatically created in a Linux directory
Default permissions for files that are automatically created in a Linux directory

Time:02-27

I have a problem with an application developed in python using the django framework, it uses the FPDF library to export a file which is then used by the application to attach it to an automated email.

When this app exports the PDF and saves it to the media directory, the file doesn't inherit permissions from its parent directory and only has read/write permissions, this doesn't allow Django to find the file so it can be attached to the mail.

I was searching on the internet and found people with the same problem, they were recommended to use the ACL configuration to manage default permissions, I tried many times with different methods but it did not work. I don't know what I could have done wrong (I kept having the same error). Dfter having made the ACL configuration the files continued to be exported with the same permissions and when applying the command chmod 777 -R * these did not change their permissions, I had to disable the ACL configuration for it to allow me to apply that command.

This is the error that appears:

Internal Server Error: /treasury/sendMailsSupplierView/SBOJOZF
Traceback (most recent call last):
  File "/var/www/johannasenvironment/venvjoh/lib/python3.6/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/var/www/johannasenvironment/venvjoh/lib/python3.6/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/var/www/johannasenvironment/JohannasEnviroment/treasuryEmails/views.py", line 33, in sendMailsSupplierView
    sendEmailSupplier('[email protected]', report) #sendEmailSupplier(emailSupplier, report)
  File "/var/www/johannasenvironment/JohannasEnviroment/treasuryEmails/mails/mailsFunctions.py", line 50, in sendEmailSupplier
    email_traslado.attach_file(report)
  File "/var/www/johannasenvironment/venvjoh/lib/python3.6/site-packages/django/core/mail/message.py", line 330, in attach_file
    with path.open('rb') as file:
  File "/usr/lib/python3.6/pathlib.py", line 1183, in open
    opener=self._opener)
  File "/usr/lib/python3.6/pathlib.py", line 1037, in _opener
    return self._accessor.open(self, flags, mode)
  File "/usr/lib/python3.6/pathlib.py", line 387, in wrapped
    return strfunc(str(pathobj), *args)
FileNotFoundError: [Errno 2] No such file or directory: 'media/PaySuppiler--27022022142925.pdf'

This is what the latest unapplied files look like sudo chmod 777 *:

administrador@WEB-APPLICATION:/var/www/johannasenvironment/JohannasEnviroment/media$ ls -l
total 396
-rw-r--r-- 1 www-data www-data 133492 feb 27 09:17 PaySuppiler--27022022141734.pdf
-rw-r--r-- 1 www-data www-data 133492 feb 27 09:28 PaySuppiler--27022022142833.pdf
-rw-r--r-- 1 www-data www-data 133492 feb 27 09:29 PaySuppiler--27022022142925.pdf
administrador@WEB-APPLICATION:/var/www/johannasenvironment/JohannasEnviroment/media$

These are the permissions of the media directory:

drwxrwxrwx  2 administrador administrador  16384 feb 27 09:29 media

CodePudding user response:

Possibly try executing the command as root?

CodePudding user response:

Can you check if the path which is being accessed is correct. As per the permissions of the files inside media folder, every user has read permission, and you are trying to read a file (in binary form).

This error (FileNotFoundError: [Errno 2] No such file or directory: 'media/PaySuppiler--27022022142925.pdf') shows that path is not correct. Try using relative path based on the file e.g os.path.join(os.path.realpath(file), "../media/PaySuppiler--27022022142925.pdf")

Why am I getting a FileNotFoundError?

  • Related