在新的生产服务器上上载文件时出现PermissionError



我将Django项目迁移到了一个新的生产服务器上。在以前的生产服务器上,一切正常。在迁移过程中,我升级到了Ubuntu 20.04和Django 4.0.3。现在,除了上传文件外,一切都恢复正常。

当我尝试创建Invoice对象的实例时,只要我不尝试上传文件,它就可以工作。添加带有文件的发票会出现以下错误:

Internal Server Error: /stock/create_invoice
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
File "/usr/local/lib/python3.8/dist-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/var/www/html/stock/views.py", line 346, in create_invoice
invoice.save()
File "/usr/local/lib/python3.8/dist-packages/django/db/models/base.py", line 806, in save
self.save_base(
File "/usr/local/lib/python3.8/dist-packages/django/db/models/base.py", line 857, in save_base
updated = self._save_table(
File "/usr/local/lib/python3.8/dist-packages/django/db/models/base.py", line 1000, in _save_table
results = self._do_insert(
File "/usr/local/lib/python3.8/dist-packages/django/db/models/base.py", line 1041, in _do_insert
return manager._insert(
File "/usr/local/lib/python3.8/dist-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/django/db/models/query.py", line 1434, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
File "/usr/local/lib/python3.8/dist-packages/django/db/models/sql/compiler.py", line 1620, in execute_sql
for sql, params in self.as_sql():
File "/usr/local/lib/python3.8/dist-packages/django/db/models/sql/compiler.py", line 1547, in as_sql
value_rows = [
File "/usr/local/lib/python3.8/dist-packages/django/db/models/sql/compiler.py", line 1548, in <listcomp>
[
File "/usr/local/lib/python3.8/dist-packages/django/db/models/sql/compiler.py", line 1549, in <listcomp>
self.prepare_value(field, self.pre_save_val(field, obj))
File "/usr/local/lib/python3.8/dist-packages/django/db/models/sql/compiler.py", line 1497, in pre_save_val
return field.pre_save(obj, add=True)
File "/usr/local/lib/python3.8/dist-packages/django/db/models/fields/files.py", line 316, in pre_save
file.save(file.name, file.file, save=False)
File "/usr/local/lib/python3.8/dist-packages/django/db/models/fields/files.py", line 92, in save
self.name = self.storage.save(name, content, max_length=self.field.max_length)
File "/usr/local/lib/python3.8/dist-packages/django/core/files/storage.py", line 57, in save
name = self._save(name, content)
File "/usr/local/lib/python3.8/dist-packages/django/core/files/storage.py", line 339, in _save
os.chmod(full_path, self.file_permissions_mode)
PermissionError: [Errno 1] Operation not permitted: '/var/www/html/media/invoices/veryniceinvoice.pdf'
Internal Server Error: /stock/invoice/0/
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
File "/usr/local/lib/python3.8/dist-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.8/dist-packages/django/contrib/auth/decorators.py", line 23, in _wrapped_view
return view_func(request, *args, **kwargs)
File "/var/www/html/stock/views.py", line 159, in invoice
invoice = Invoice.objects.get(pk=invoice_id)
File "/usr/local/lib/python3.8/dist-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/django/db/models/query.py", line 496, in get
raise self.model.DoesNotExist(
stock.models.Invoice.DoesNotExist: Invoice matching query does not exist.

文件已上载到正确的(cifs已安装(文件夹,但由于某种原因,无法将包含文件链接的对象实例添加到数据库中?

我想问题出在某种许可问题上。我试着通过将所有设置为777来解决这个问题,这样我至少可以看看这是否解决了问题,但事实并非如此。/var/www/html/media的文件夹权限当前为:

drwxrwxrwx 2根目录0 3月17日08:57发票

chown由于某种原因不起作用(我读到这与cifs装载有关?(,但var-www也不是以前服务器上发票文件夹的所有者,这很好。。。

任何帮助都将不胜感激!

我找到了解决方案。

我不得不将uid=www data,forceuid添加到cifs mount命令中。apache用户没有正确的权限。

(然后卸载,然后再次装载(

相关内容

  • 没有找到相关文章

最新更新