question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

See original GitHub issue

I 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:closed
  • Created 2 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
adamchainzcommented, Mar 2, 2022

That sounds like a legitimate explanation!

it’s choking on (perfectly valid) unicode characters

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.

1reaction
evansdcommented, Mar 2, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

error UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff ...
Python tries to convert a byte-array (a bytes which it assumes to be a utf-8-encoded string) to a unicode string ( str )....
Read more >
'utf-8' codec can't decode byte 0xff in position 0 | bobbyhadz
The Python "UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte" occurs when we specify an incorrect ...
Read more >
How to fix error UnicodeDecodeError utf 8 codec cant decode ...
How to Fix Error "UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte" in Python. The below error is...
Read more >
'utf-8' codec can't decode byte 0xff in position 0 - Non-DQ ...
What this error tells you is that the encoding you used when opening the file, doesn't match the actually encoding of the file...
Read more >
'utf-8' codec can't decode byte 0xff in position 0: invalid start ...
UnicodeDecodeError : 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte #2499. Closed. lukehodges opened this issue on Sep 17 ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found