当我运行 python manage.py runserver 代码时出现错误。它的回溯很奇怪,和所有类似的问题,但没有得到我到底面临什么。Traceback (most recent call last): File "manage.py", line 22, in <module> execute_from_command_line(sys.argv) File "/home/tousif/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line utility.execute() File "/home/tousif/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 308, in execute settings.INSTALLED_APPS File "/home/tousif/.local/lib/python2.7/site-packages/django/conf/__init__.py", line 56, in __getattr__ self._setup(name) File "/home/tousif/.local/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup self._wrapped = Settings(settings_module) File "/home/tousif/.local/lib/python2.7/site-packages/django/conf/__init__.py", line 110, in __init__ mod = importlib.import_module(self.SETTINGS_MODULE) File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) File "/home/tousif/Desktop/ITP/ITP/itpcrm/itpcrm/settings.py", line 55, in <module> cfg = json.loads(open('/home/tousif/Desktop/ITP/ITP/itpcrm/config.json', 'r').read()) File "/usr/lib/python2.7/json/__init__.py", line 339, in loads return _default_decoder.decode(s) File "/usr/lib/python2.7/json/decoder.py", line 364, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python2.7/json/decoder.py", line 380, in raw_decode obj, end = self.scan_once(s, idx)ValueError: Expecting property name: line 4 column 1 (char 43)我的 config.json 文件包含凭据等(我已将凭据更改为在此处发布)。并从实时服务器获取此文件,该文件工作正常,但在本地却出现此错误。{ "dev": { "db": { "ENGINE": "django.db.backends.mysql", "NAME": "itpcrm", "USER": "root", "PASSWORD": "password", "HOST": "localhost", "PORT": "3306" },
1 回答
潇潇雨雨
TA贡献1833条经验 获得超4个赞
"db" 之后的空行以 unicode 代码点 0x200B ('ZERO WIDTH SPACE') 开始。这就是 JSON 解码器的绊脚石。
我将文本复制到其中gvim
并制作了屏幕截图。见下文。
删除这些字符(或整行),它的工作原理......
(使用十六进制编辑器查看 JSON 文件也会清楚地显示问题。)
如果您仔细查看错误消息,您可以正确识别问题:
ValueError:期望属性名称:第 4 行第 1 列(字符 43)
这个故事的寓意是:注意空白代码点。
添加回答
举报
0/150
提交
取消