ValueError: 源代码字符串不能包含空字节 -django

问题描述

这是我每次尝试运行服务器时得到的回溯。

C:\Users\Sarathmahe024\Downloads\website (1)\website\website>python manage.py runserver
 

Traceback (most recent call last):
  File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\core\management\__init__.py",line 357,in execute
autoreload.check_errors(django.setup)()
 File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\utils\autoreload.py",line 53,in wrapper
fn(*args,**kwargs)
  File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\__init__.py",line 16,in setup
from django.urls import set_script_prefix
  File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\urls\__init__.py",line 1,in <module>
from .base import (
 File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\urls\base.py",line 9,in <module>
from .exceptions import noreverseMatch,Resolver404
 File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\urls\exceptions.py",in <module>
from django.http import Http404
 File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\http\__init__.py",line 5,in <module>
from django.http.response import (
 File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\http\response.py",line 15,in <module>
from django.core.serializers.json import DjangoJSONEncoder
 File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\core\serializers\__init__.py",line 23,in <module>
from django.core.serializers.base import SerializerDoesNotExist
 File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\core\serializers\base.py",line 7,in <module>
from django.db import models
 File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\db\models\__init__.py",line 3,in <module>
from django.db.models.aggregates import *  # NOQA
 File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\db\models\aggregates.py",in <module>
from django.db.models.expressions import Case,Func,Star,When
 File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\db\models\expressions.py",line 8,in <module>
from django.db.models import fields
 File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\db\models\fields\__init__.py",line 11,in <module>
from django import forms
 File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\forms\__init__.py",line 6,in <module>
from django.forms.boundfield import *  # NOQA
ValueError: source code string cannot contain null bytes

During handling of the above exception,another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Sarathmahe024\Downloads\website (1)\website\website\manage.py",line 22,in <module>
execute_from_command_line(sys.argv)
  File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\core\management\__init__.py",line 401,in execute_from_command_line

utility.execute()
  File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\core\management\__init__.py",line 370,in execute
_parser = self.fetch_command('runserver').create_parser('django','runserver')
  File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\core\management\__init__.py",line 244,in fetch_command
klass = load_command_class(app_name,subcommand)
  File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\core\management\__init__.py",line 37,in load_command_class
module = import_module('%s.management.commands.%s' % (app_name,name))
 File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\importlib\__init__.py",line 127,in import_module
return _bootstrap._gcd_import(name[level:],package,level)
  File "<frozen importlib._bootstrap>",line 1030,in _gcd_import
  File "<frozen importlib._bootstrap>",line 1007,in _find_and_load
  File "<frozen importlib._bootstrap>",line 986,in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>",line 680,in _load_unlocked
  File "<frozen importlib._bootstrap_external>",line 790,in exec_module
  File "<frozen importlib._bootstrap>",line 228,in _call_with_frames_removed
  File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\core\management\commands\runserver.py",line 10,in <module>
from django.core.servers.basehttp import (
  File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\core\servers\basehttp.py",line 17,in <module>
from django.core.handlers.wsgi import LimitedStream
  File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\core\handlers\wsgi.py",in <module>
from django.core.handlers import base
  File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\core\handlers\base.py",in <module>
from django.urls import get_resolver,set_URLconf
  File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\urls\__init__.py",in <module>
from .base import (
  File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\urls\base.py",Resolver404
  File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\urls\exceptions.py",in <module>
from django.http import Http404
  File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\http\__init__.py",in <module>
from django.http.response import (
  File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\http\response.py",in <module>
from django.core.serializers.json import DjangoJSONEncoder
  File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\core\serializers\__init__.py",in <module>
from django.core.serializers.base import SerializerDoesNotExist
  File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\core\serializers\base.py",in <module>
from django.db import models
  File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\db\models\__init__.py",in <module>
from django.db.models.aggregates import *  # NOQA
  File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\db\models\aggregates.py",When
  File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\db\models\expressions.py",in <module>
from django.db.models import fields
  File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\db\models\fields\__init__.py",in <module>
from django import forms
  File "C:\Users\Sarathmahe024\AppData\Local\Programs\Python\python39\lib\site-packages\django\forms\__init__.py",in <module>
from django.forms.boundfield import *  # NOQA
ValueError: source code string cannot contain null bytes

几个月前我遇到了同样的错误。然后我尝试重新安装对我有用的 pycharm。 我只是在这里尝试了相同的方法,但没有解决。真的很困惑什么可能是错误。 任何人都可以提出一种摆脱此错误方法。 提前致谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)