gpt4 book ai didi

python - Django makemessages "struct.error: unpack requires a buffer of 4 bytes"

转载 作者:行者123 更新时间:2023-12-01 01:21:31 30 4
gpt4 key购买 nike

我有一个 django 实例打包在 docker-compose 中的 Docker 容器中。

我正在尝试为项目生成 makemessages 文件,但是当我尝试运行 makemessages 时,这就是我收到的响应

root@6fc510c9c5d1:/code# python manage.py makemessages
/usr/local/lib/python3.6/dist-packages/daphne/server.py:12: UserWarning: Something has already installed a non-asyncio Twisted reactor. Attempting to uninstall it; you can fix this warning by importing daphne.server early in your codebase or finding the package that imports Twisted and importing it later on.
UserWarning,
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 347, in execute
django.setup()
File "/usr/local/lib/python3.6/dist-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.6/dist-packages/django/apps/registry.py", line 112, in populate
app_config.import_models()
File "/usr/local/lib/python3.6/dist-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/usr/local/lib/python3.6/dist-packages/django/contrib/auth/models.py", line 94, in <module>
class Group(models.Model):
File "/usr/local/lib/python3.6/dist-packages/django/db/models/base.py", line 152, in __new__
new_class.add_to_class(obj_name, obj)
File "/usr/local/lib/python3.6/dist-packages/django/db/models/base.py", line 315, in add_to_class
value.contribute_to_class(cls, name)
File "/usr/local/lib/python3.6/dist-packages/django/db/models/fields/related.py", line 1586, in contribute_to_class
self.remote_field.through = create_many_to_many_intermediary_model(self, cls)
File "/usr/local/lib/python3.6/dist-packages/django/db/models/fields/related.py", line 1051, in create_many_to_many_intermediary_model
'verbose_name': _('%(from)s-%(to)s relationship') % {'from': from_, 'to': to},
File "/usr/local/lib/python3.6/dist-packages/django/utils/functional.py", line 148, in __mod__
return str(self) % rhs
File "/usr/local/lib/python3.6/dist-packages/django/utils/functional.py", line 112, in __text_cast
return func(*self.__args, **self.__kw)
File "/usr/local/lib/python3.6/dist-packages/django/utils/translation/__init__.py", line 77, in gettext
return _trans.gettext(message)
File "/usr/local/lib/python3.6/dist-packages/django/utils/translation/trans_real.py", line 312, in gettext
_default = _default or translation(settings.LANGUAGE_CODE)
File "/usr/local/lib/python3.6/dist-packages/django/utils/translation/trans_real.py", line 221, in translation
_translations[language] = DjangoTranslation(language)
File "/usr/local/lib/python3.6/dist-packages/django/utils/translation/trans_real.py", line 122, in __init__
self._add_installed_apps_translations()
File "/usr/local/lib/python3.6/dist-packages/django/utils/translation/trans_real.py", line 170, in _add_installed_apps_translations
translation = self._new_gnu_trans(localedir)
File "/usr/local/lib/python3.6/dist-packages/django/utils/translation/trans_real.py", line 149, in _new_gnu_trans
fallback=use_null_fallback)
File "/usr/lib/python3.6/gettext.py", line 538, in translation
t = _translations.setdefault(key, class_(fp))
File "/usr/lib/python3.6/gettext.py", line 254, in __init__
self._parse(fp)
File "/usr/lib/python3.6/gettext.py", line 345, in _parse
magic = unpack('<I', buf[:4])[0]
struct.error: unpack requires a buffer of 4 bytes

你有什么想法吗?

最佳答案

它可能是由您的 .mo 文件引发的。请检查该文件是否为空。如果确实如此的话。删除 .mo 文件并重新运行 makemessages 命令。

它应该可以解决您遇到的问题。

如果这不能解决您的问题。试试这个:

  1. 将所有 .po 文件保存在不同位置(创建区域设置文件的备份)
  2. 删除 locale 文件夹中的所有语言。
  3. 重新运行命令

关于python - Django makemessages "struct.error: unpack requires a buffer of 4 bytes",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53793985/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com