gpt4 book ai didi

python - Django "ValueError: embedded null byte"

转载 作者:行者123 更新时间:2023-12-01 07:47:19 27 4
gpt4 key购买 nike

我刚刚安装了Django,并在settings.py中将数据库从sqlite3更改为mysql,但是当我运行服务器时,偶尔会出现“ValueError:嵌入空字节”。我该怎么办?

  • Python 3.6.1
  • Django 版本 2.2.1
(myproject) bash-3.2$ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 60, in execute
super().execute(*args, **options)
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 95, in handle
self.run(**options)
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 102, in run
autoreload.run_with_reloader(self.inner_run, **options)
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/utils/autoreload.py", line 577, in run_with_reloader
start_django(reloader, main_func, *args, **kwargs)
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/utils/autoreload.py", line 562, in start_django
reloader.run(django_main_thread)
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/utils/autoreload.py", line 280, in run
self.run_loop()
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/utils/autoreload.py", line 286, in run_loop
next(ticker)
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/utils/autoreload.py", line 326, in tick
for filepath, mtime in self.snapshot_files():
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/utils/autoreload.py", line 342, in snapshot_files
for file in self.watched_files():
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/utils/autoreload.py", line 241, in watched_files
yield from iter_all_python_module_files()
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/utils/autoreload.py", line 103, in iter_all_python_module_files
return iter_modules_and_files(modules, frozenset(_error_files))
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/utils/autoreload.py", line 132, in iter_modules_and_files
results.add(path.resolve().absolute())
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pathlib.py", line 1122, in resolve
s = self._flavour.resolve(self, strict=strict)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pathlib.py", line 349, in resolve
return _resolve(base, str(path)) or sep
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pathlib.py", line 331, in _resolve
target = accessor.readlink(newpath)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pathlib.py", line 443, in readlink
return os.readlink(path)
ValueError: embedded null byte

最佳答案

我有同样的问题,调试它看起来是由于在 v2.2.0 中引入 watchman 引起的,因为降级到 v1.9.0 删除了它。

奇怪的是,有时服务器会启动,该错误似乎并不是每次都会发生,但我相当确定这是由于虚拟环境造成的。

修复:

禁用重新加载(不理想)

python manage.py runserver --noreload

创建一个 watchman 配置并忽略 venv

https://docs.djangoproject.com/en/2.2/ref/django-admin/#runserver

https://facebook.github.io/watchman/docs/config.html#ignore_dirs

但是我实际上无法让ignore_dirs工作......

Django 门票

https://code.djangoproject.com/ticket/30506

关于python - Django "ValueError: embedded null byte",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56406965/

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