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

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

2024-04-30 12:04:13 前端知识 前端哥 225 333 我要收藏

源代码如下
在这里插入图片描述
报错信息:
从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)
转载请注明出处或者链接地址:https://www.qianduange.cn//article/6762.html
评论
发布的文章

JQuery中的load()、$

2024-05-10 08:05:15

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!