UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
See original GitHub issueI am trying to push my django project to heroku but each time i try to python manage.py collectstatic
, I am get this error every time i set STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
YET When i run python manage.py collectstatic
with the default STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage
’
It runs without an issue.
I originally thought one/some of my static files had issues and went through each and everyone of the tens of files but still got the same error.
Then i decided to default the STATICFILES_STORAGE
setting and to my surprise, python manage.py collectstatic
worked.
I would like for someone to help me trouble shoot on this one. Because the issue seems to be related to whitenoise.
I am using Python 3.9.4 and django 3.2
Below is the error i am getting.
Traceback (most recent call last):
File "/home/nmj/PROJECTS/abc/blueMust/mysite/src/manage.py", line 22, in <module>
main()
File "/home/nmj/PROJECTS/abc/blueMust/mysite/src/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/nmj/PROJECTS/abc/SubmissionMgtSyst/mysite/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/home/nmj/PROJECTS/abc/SubmissionMgtSyst/mysite/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/nmj/PROJECTS/abc/SubmissionMgtSyst/mysite/venv/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/nmj/PROJECTS/abc/SubmissionMgtSyst/mysite/venv/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/home/nmj/PROJECTS/abc/SubmissionMgtSyst/mysite/venv/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 187, in handle
collected = self.collect()
File "/home/nmj/PROJECTS/abc/SubmissionMgtSyst/mysite/venv/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 128, in collect
for original_path, processed_path, processed in processor:
File "/home/nmj/PROJECTS/abc/SubmissionMgtSyst/mysite/venv/lib/python3.9/site-packages/whitenoise/storage.py", line 148, in post_process_with_compression
for name, hashed_name, processed in files:
File "/home/nmj/PROJECTS/abc/SubmissionMgtSyst/mysite/venv/lib/python3.9/site-packages/whitenoise/storage.py", line 88, in post_process
for name, hashed_name, processed in files:
File "/home/nmj/PROJECTS/abc/SubmissionMgtSyst/mysite/venv/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 406, in post_process
yield from super().post_process(*args, **kwargs)
File "/home/nmj/PROJECTS/abc/SubmissionMgtSyst/mysite/venv/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 231, in post_process
for name, hashed_name, processed, _ in self._post_process(paths, adjustable_paths, hashed_files):
File "/home/nmj/PROJECTS/abc/SubmissionMgtSyst/mysite/venv/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 288, in _post_process
content = original_file.read().decode("utf-8") # original line
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (2 by maintainers)
That sounds like a legitimate explanation!
Are you sure they’re valid? Django is just doing a plain read-and-decode. If you run that yourself for the same file, it should raise the same error.
I assume this is because Django now tries to rewrite source map references inside JS files, so it now has to read JS files which it never did before: https://docs.djangoproject.com/en/4.0/releases/4.0/#django-contrib-staticfiles