简体   繁体   English

在 Linux 目录中自动创建的文件的默认权限

[英]Default permissions for files that are automatically created in a Linux directory

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.我在 python 中使用 django 框架开发的应用程序有问题,它使用 FPDF 库导出文件,然后应用程序使用该文件将其附加到自动 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.本应用导出PDF并保存到media目录时,该文件不继承其父目录的权限,只有读/写权限,这不允许Django找到该文件,因此可以附加到邮件。

I was searching on the inte.net 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.我在网上搜索,发现有人有同样的问题,他们建议使用ACL配置来管理默认权限,我用不同的方法尝试了很多次,但都没有用。 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.在进行 ACL 配置后,文件继续以相同的权限导出,并且在应用命令chmod 777 -R *时,这些文件没有更改它们的权限,我不得不禁用它的 ACL 配置以允许我应用该命令。

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('narvaezsebas8@gmail.com', 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 * :这是最新的未应用文件的样子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:这些是media目录的权限:

drwxrwxrwx  2 administrador administrador  16384 feb 27 09:29 media

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.此错误 (FileNotFoundError: [Errno 2] No such file or directory: 'media/PaySuppiler--27022022142925.pdf') 表明路径不正确。 Try using relative path based on the file eg os.path.join(os.path.realpath( file ), "../media/PaySuppiler--27022022142925.pdf")尝试使用基于文件的相对路径,例如 os.path.join(os.path.realpath( file ), "../media/PaySuppiler--27022022142925.pdf")

Why am I getting a FileNotFoundError? 为什么我会收到 FileNotFoundError?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM