raise SuspiciousFileOperation("Could not derive file name from '%s'" % name) on Running collectstatic command

82 views
Skip to first unread message

Maadis Ie

unread,
Jul 23, 2024, 11:29:58 AM7/23/24
to Django users
Hi, 
I am trying to deploy my first Django app (5.0.7). When I run 'python mange.py collectstatic' it copies some of the admin and css files and exit with the following error message:

"python manage.py collectstatic

You have requested to collect static files at the destination
location as specified in your settings:

    /webapps/dsite/dcork.ie/dproject/staticfiles

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes
Traceback (most recent call last):
  File "/webapps/dsite/dcork.ie/dproject/manage.py", line 22, in <module>
    main()
  File "/webapps/dsite/dcork.ie/dproject/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/webapps/dsite/dcork.ie/virt/lib/python3.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/webapps/dsite/dcork.ie/virt/lib/python3.12/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/webapps/dsite/dcork.ie/virt/lib/python3.12/site-packages/django/core/management/base.py", line 413, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/webapps/dsite/dcork.ie/virt/lib/python3.12/site-packages/django/core/management/base.py", line 459, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/webapps/dsite/dcork.ie/virt/lib/python3.12/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 209, in handle
    collected = self.collect()
                ^^^^^^^^^^^^^^
  File "/webapps/dsite/dcork.ie/virt/lib/python3.12/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 135, in collect
    handler(path, prefixed_path, storage)
  File "/webapps/dsite/dcork.ie/virt/lib/python3.12/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 378, in copy_file
    self.storage.save(prefixed_path, source_file)
  File "/webapps/dsite/dcork.ie/virt/lib/python3.12/site-packages/django/core/files/storage/base.py", line 44, in save
    name = self.get_available_name(name, max_length=max_length)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/webapps/dsite/dcork.ie/virt/lib/python3.12/site-packages/django/core/files/storage/base.py", line 82, in get_available_name
    validate_file_name(file_name)
  File "/webapps/dsite/dcork.ie/virt/lib/python3.12/site-packages/django/core/files/utils.py", line 10, in validate_file_name
    raise SuspiciousFileOperation("Could not derive file name from '%s'" % name)
django.core.exceptions.SuspiciousFileOperation: Could not derive file name from ''

Has anybody entered this error? I am getting this error both on Nginx alone and Whitenoise. It copies some files in the destination directory before this error.  

Any pointers would be highly appreciated.
Thanks, 

Amitesh Sahay

unread,
Jul 24, 2024, 3:30:02 AM7/24/24
to Django users
Please my reply below

The error SuspiciousFileOperation: Could not derive file name from '' indicates that a file operation is being attempted without a valid file name. This can occur if a file is being saved or uploaded with an empty or invalid name.

Regards,
Amitesh 


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/65c45fc1-2bb8-4175-a796-05223023f28fn%40googlegroups.com.

Maadis

unread,
Jul 25, 2024, 4:31:58 AM7/25/24
to Django users
Thanks, Amitesh, for this info. It makes sense to me now!

Since nothing worked, I manually copied all the necessary libraries to a folder where the NginX serves its static files—it worked. However, while I was copying those files, I had noticed a file with an empty name (shown as '/' in the Linux system) in one of my folders!

I will test this in another environment with the above info in mind.

Thanks once again.
With regards,
Maadis
Reply all
Reply to author
Forward
0 new messages