源代码如下
报错信息:
从graph.run这里报错,报出一个JSon相关的错误,百思不得其解。
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)
解决方法:
需要加上一个name=“neo4j”,才能成功,如下
graph = Graph("http://localhost:7474",user= "neo4j",password = "zhang123",name="neo4j")
或者这样
graph = Graph("http://localhost:7474",auth=("neo4j","zhang123"),name="neo4j")
完整demo
from py2neo import Graph
#连接图数据库
graph = Graph("http://localhost:7474",user= "neo4j",password = "zhang123",name="neo4j")
cypher = "create (n:person {name : '老大',age : 18,length : 168})"
graph.run(cypher)