环境为neo4j-enterprise-5.1.0、py2neo、Neo4j Desktop-1.5.2
Traceback (most recent call last):
File "D:\software\Python\Python37\lib\site-packages\py2neo\client\http.py", line 443, in from_json
content = json_loads(data, object_hook=JSONHydrant.json_to_packstream)
File "D:\software\Python\Python37\lib\json\__init__.py", line 361, in loads
return cls(**kw).decode(s)
File "D:\software\Python\Python37\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "D:\software\Python\Python37\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:/work/Python/Neo4j2Web/add_atrr/english_name.py", line 17, in <module>
g.run("MATCH (m:AgriculturePest { name: '" + i + "'}) SET m += {english_name: '" + j + "'}")
File "D:\software\Python\Python37\lib\site-packages\py2neo\database.py", line 405, in run
return self.auto().run(cypher, parameters, **kwparameters)
File "D:\software\Python\Python37\lib\site-packages\py2neo\database.py", line 992, in run
readonly=self.readonly)
File "D:\software\Python\Python37\lib\site-packages\py2neo\client\__init__.py", line 1340, in auto_run
return cx.auto_run(cypher, parameters, graph_name=graph_name, readonly=readonly)
File "D:\software\Python\Python37\lib\site-packages\py2neo\client\http.py", line 177, in auto_run
rs = HTTPResponse.from_json(r.status, r.data.decode("utf-8"))
File "D:\software\Python\Python37\lib\site-packages\py2neo\client\http.py", line 445, in from_json
raise_from(ProtocolError("Cannot decode response content as JSON"), error)
File "" , line 3, in raise_from
py2neo.errors.ProtocolError: Cannot decode response content as JSON
进程已结束,退出代码为 1
根据堆栈追踪,我们发现self.graph.name为空,而self.graph为Graph("http://localhost:7474/ ")
所以我们自己修改源码
打开python的包的安装位置:
X:*****\Python\Python37\Lib\site-packages\py2neo\database.py
原来的代码: (990行左右)
result = self._connector.auto_run(cypher, parameters,
graph_name=self.graph.name,
readonly=self.readonly)
更改后的代码:
result = self._connector.auto_run(cypher, parameters,
graph_name="neo4j",
readonly=self.readonly)