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

时间:2016-08-02 21:55:17

标签: python django

与团队一起处理一个相当大/复杂的Django项目时,我们偶尔会看到ValueError: embedded null byte的runserver崩溃。我们重新启动runserver,它很好 - 无论是几分钟还是几天。我们可以检测到没有导致崩溃的模式(似乎完全随机)。幸运的是,它只发生在本地开发中,而不是发生在我们的服务器上,但我担心它会让我们陷入困境。

下面的堆栈跟踪并未指向我们代码中的任何位置 - 似乎来自Django或virtualenv本身。

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

我看不到任何调试方法。理论?

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

1 个答案:

答案 0 :(得分:4)

  • 其中一个=if(A2="L", if(now()-B2>=84, "Need to reach out!", if(now()-b2>=70, "Schedule a call!", if(now()-B2<56, "Communications up to date", "" ) ) ), if(A2="M", if(now()-b2>=42, "Need to reach out!", if(now()-b2>=28, "Schedule a call!", "Communications up to date" ) ), if(A2="H", if(now()-b2>=21, "Need to reach out!", if(now()-b2>=14, "Schedule a call!", "Communications up to date" ) ) ) ) )& if(C2="scheduled", " - Communication Scheduled", "" ) 对象的AppConfig属性中包含空字节。
  • 其中一个path有空字节。
  • 其中一个文件采用“错误”编码,因此Django会将某些内容视为空字节(例如LOCALE_PATHS)。
  • 项目目录中的一个文件或目录名称中包含空字节(AppConfig.path)。
  • 其他原因。

autoreload.py lines与此问题有关。 \x00如果其参数为空字节,则引发os.path.isdir(),e。 G。 ValueError: embedded null byte

您可以尝试修改os.path.isdir('foo\x00bar'),暂时注释掉这些行:

autoreload.py

并添加:

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