源代码如下
报错信息:
从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")
或者这样文章来源:https://www.toymoban.com/news/detail-502414.html
graph = Graph("http://localhost:7474",auth=("neo4j","zhang123"),name="neo4j")
完整demo文章来源地址https://www.toymoban.com/news/detail-502414.html
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)
到了这里,关于【知识图谱】python连接neo4j报错:py2neo.errors.ProtocolError: Cannot decode response content as JSON的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!