尝试运行collectstatic时出现UnicodeDecodeError - 使用Django

时间:2018-03-30 18:34:03

标签: django python-3.x unicode django-staticfiles

我在尝试将项目推送到Heroku时得到UnicodeDecodeError。当我尝试在控制台中运行collectstatic时,我也收到此错误。我不知道是什么原因引起的。我还是新人,通过阅读追溯我无法弄明白。我正在使用whitenoise来存储我的静态数据。如果你可以帮助我解决问题可能是什么,那将是非常棒的。这是追溯:

$ python manage.py collectstatic --noinput
remote:        Traceback (most recent call last):
remote:          File "manage.py", line 15, in <module>
remote:            execute_from_command_line(sys.argv)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
remote:            utility.execute()
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute
remote:            self.fetch_command(subcommand).run_from_argv(self.argv)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv
remote:            self.execute(*args, **cmd_options)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 335, in execute
remote:            output = self.handle(*args, **options)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 189, in handle
remote:            collected = self.collect()
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 129, in collect
remote:            for original_path, processed_path, processed in processor:
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/whitenoise/storage.py", line 67, in post_process
remote:            for name, hashed_name, processed in files:
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/whitenoise/storage.py", line 29, in post_process_with_compression
remote:            for name, hashed_name, processed in files:
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 405, in post_process
remote:            yield from super().post_process(*args, **kwargs)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 239, in post_process
remote:            for name, hashed_name, processed, _ in self._post_process(paths, adjustable_paths, hashed_files):
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 290, in _post_process
remote:            content = original_file.read().decode(settings.FILE_CHARSET)
remote:        UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
remote:
remote:  !     Error while running '$ python manage.py collectstatic --noinput'.

1 个答案:

答案 0 :(得分:0)

我的一个CSS文件编码方式不同。我刚刚从static \ css文件夹中删除了文件,直到找到导致错误的文件,并更改了它。