2017-09-25 32 views
0

從未見過類似的東西。當我在Ubuntu終端上的Django應用程序做python manage.py syncdb,我看到:錯誤:使用syncdb遷移時,解包需要長度爲4的字符串參數錯誤

error: unpack requires a string argument of length 4

我不知道這意味着什麼或如何解決它。


>  Traceback (most recent call last): 
>  File "/home/ubuntu/.virtualenvs/myenv/local/lib/python2.7/site-packages/django/core/management/base.py", 
> line 222, in run_from_argv 
>   self.execute(*args, **options.__dict__) 
>  File "/home/ubuntu/.virtualenvs/myenv/local/lib/python2.7/site-packages/django/core/management/base.py", 
> line 250, in execute 
>   translation.activate('en-us') 
>  File "/home/ubuntu/.virtualenvs/myenv/local/lib/python2.7/site-packages/django/utils/translation/__init__.py", 
> line 90, in activate 
>   return _trans.activate(language) 
>  File "/home/ubuntu/.virtualenvs/myenv/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", 
> line 183, in activate 
>   _active.value = translation(language) 
>  File "/home/ubuntu/.virtualenvs/myenv/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", 
> line 172, in translation 
>   default_translation = _fetch(settings.LANGUAGE_CODE) 
>  File "/home/ubuntu/.virtualenvs/myenv/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", 
> line 133, in _fetch 
>   res = _translation(globalpath) 
>  File "/home/ubuntu/.virtualenvs/myenv/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", 
> line 127, in _translation 
>   t = gettext_module.translation('django', path, [loc], DjangoTranslation) 
>  File "/usr/lib/python2.7/gettext.py", line 493, in translation 
>   t = _translations.setdefault(key, class_(fp)) 
>  File "/home/ubuntu/.virtualenvs/myenv/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", 
> line 75, in __init__ 
>   gettext_module.GNUTranslations.__init__(self, *args, **kw) 
>  File "/usr/lib/python2.7/gettext.py", line 180, in __init__ 
>   self._parse(fp) 
>  File "/usr/lib/python2.7/gettext.py", line 273, in _parse 
>   magic = unpack('<I', buf[:4])[0] 
>  error: unpack requires a string argument of length 4 

而且manage.py只包含:

#!/usr/bin/env python 
import os 
import sys 

if __name__ == "__main__": 
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings") 

    from django.core.management import execute_from_command_line 

    execute_from_command_line(sys.argv) 
+2

請讓我們知道您正在使用的Django版本,併發布異常追蹤。 (如果您沒有看到回溯,請將'--traceback'添加到syncdb命令中。) – AKX

回答

1

根據回溯(感謝:)),這個問題從Django中加載其翻譯文件(的Gettext的.mo文件)的莖。

由於magic = unpack('<I', buf[:4])[0]錯誤與「錯誤:解壓縮需要長度爲4的字符串參數」,buf可能短於4個字節。這可能(這裏只是一個假設)意味着有一個截斷的.mo文件在Django試圖加載和失敗的地方。

我建議嘗試重新創建項目的virtualenv,如果這是一個選項 - 或作爲一個創可貼,您可以暫時禁用Django的i18n位。 (USE_I18N = False

+0

感謝您在好友中敲打。由於我只是在測試服務器上進行實驗,因此我將使用全新的virtualenv安裝 - 這絕對是一種選擇。我會回覆發生了什麼。手指交叉!我認爲這是一個不可知論的問題。 –