【发布时间】:2018-09-09 19:12:07
【问题描述】:
我在尝试将我的项目推送到 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'.
【问题讨论】:
-
某些文件正在使用错误的编解码器进行解码:设置说应该使用 UTF-8,但显然该文件是使用不同的编解码器存储的(可能是 UTF-16,因为第一个字节是 @ 987654325@)。不幸的是,错误消息和回溯不告诉这是关于哪个文件。但是你一定要检查静态文件的编码。
-
谢谢你。我最终弄清楚它是哪个文件并更改了。
标签: django python-3.x unicode django-staticfiles