【知识图谱】python连接neo4j报错:py2neo.errors.ProtocolError: Cannot decode response content as JSON

源代码如下
【知识图谱】python连接neo4j报错:py2neo.errors.ProtocolError: Cannot decode response content as JSON_第1张图片
报错信息:
从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)

你可能感兴趣的:(NLP/知识图谱,neo4j,知识图谱,python)