简体   繁体   English

神秘的“嵌入空字节”错误

[英]Mysterious “embedded null byte” error

Working on a fairly large/complex Django project with a team, we occasionally see runserver crash with ValueError: embedded null byte . 在团队中处理一个相当大/复杂的Django项目时,我们偶尔会看到带有ValueError: embedded null byte runserver崩溃ValueError: embedded null byte We restart runserver and it's fine - either for a few minutes or a few days. 我们重新启动runserver,它很好 - 无论是几分钟还是几天。 We can detect no pattern to what causes the crashes (seems totally random). 我们可以检测到没有导致崩溃的模式(似乎完全随机)。 Fortunately it's only happening in local development, not on our servers, but I'm worried that it will bite us down the road. 幸运的是,它只发生在本地开发中,而不是发生在我们的服务器上,但我担心它会让我们陷入困境。

The stack trace below does not point to any location in our code -- seems to come either from Django or the virtualenv itself. 下面的堆栈跟踪并未指向我们代码中的任何位置 - 似乎来自Django或virtualenv本身。

Using Django 1.9.8, Python 3.5.0, on El Capitan. 在El Capitan上使用Django 1.9.8,Python 3.5.0。

I can't see any way to debug this. 我看不出任何调试方法。 Theories? 理论?

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/path/to/virtualenvs/ourproj/lib/python3.5/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/path/to/virtualenvs/ourproj/lib/python3.5/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/path/to/virtualenvs/ourproj/lib/python3.5/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/path/to/virtualenvs/ourproj/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 54, in execute
    super(Command, self).execute(*args, **options)
  File "/path/to/virtualenvs/ourproj/lib/python3.5/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/path/to/virtualenvs/ourproj/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 93, in handle
    self.run(**options)
  File "/path/to/virtualenvs/ourproj/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 102, in run
    autoreload.main(self.inner_run, None, options)
  File "/path/to/virtualenvs/ourproj/lib/python3.5/site-packages/django/utils/autoreload.py", line 333, in main
    reloader(wrapped_main_func, args, kwargs)
  File "/path/to/virtualenvs/ourproj/lib/python3.5/site-packages/django/utils/autoreload.py", line 299, in python_reloader
    reloader_thread()
  File "/path/to/virtualenvs/ourproj/lib/python3.5/site-packages/django/utils/autoreload.py", line 275, in reloader_thread
    change = fn()
  File "/path/to/virtualenvs/ourproj/lib/python3.5/site-packages/django/utils/autoreload.py", line 204, in code_changed
    for filename in gen_filenames():
  File "/path/to/virtualenvs/ourproj/lib/python3.5/site-packages/django/utils/autoreload.py", line 114, in gen_filenames
    basedirs = [os.path.abspath(basedir) for basedir in basedirs
  File "/path/to/virtualenvs/ourproj/lib/python3.5/site-packages/django/utils/autoreload.py", line 115, in <listcomp>
    if os.path.isdir(basedir)]
  File "/path/to/virtualenvs/ourproj/bin/../lib/python3.5/genericpath.py", line 42, in isdir
    st = os.stat(s)
ValueError: embedded null byte
  • One of the AppConfig objects has null byte in its path attribute. 其中一个AppConfig对象的path属性中包含空字节。
  • One of the LOCALE_PATHS has null byte. 其中一个LOCALE_PATHS具有空字节。
  • One of the files is in the "wrong" encoding, so Django treats something has null byte (eg AppConfig.path ). 其中一个文件采用“错误”编码,因此Django会将某些内容置于空字节(例如AppConfig.path )。
  • One of the files or directories in project directory has null byte ( \\x00 ) in its name. 项目目录中的一个文件或目录名称中包含空字节( \\x00 )。
  • Other reason. 其他原因。

autoreload.py lines related to this issue. 与此问题相关的autoreload.py os.path.isdir() raises ValueError: embedded null byte if its argument has null byte, eg os.path.isdir('foo\\x00bar') . os.path.isdir()引发ValueError: embedded null byte如果其参数具有空字节,则为ValueError: embedded null byte ,例如os.path.isdir('foo\\x00bar')

You can try to edit autoreload.py , comment out these lines temporarily: 您可以尝试编辑autoreload.py ,暂时注释掉这些行:

basedirs = [os.path.abspath(basedir) for basedir in basedirs
            if os.path.isdir(basedir)]

and add this: 并添加这个:

temp_basedirs = []
for basedir in basedirs:
    try:
        if os.path.isdir(basedir):
            temp_basedirs.append(os.path.abspath(basedir))
    except ValueError:
        print(basedir)
        raise
basedirs = temp_basedirs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM