我是 py2neo 的新手。 尝试创建一个包含一些节点的 KG,例如
graph = Graph('http://127.0.0.1:7474/', name="test", password="12345678")
node1 = Node('Person', name='Bob')
graph.create(node1)
但我得到一个
KeyError: 'location'
,详细:
Traceback (most recent call last):
File "D:\PyCharm-workspace\learn_Neo4j\test.py", line 23, in <module>
graph.create(node4)
File "D:\python3.8\lib\site-packages\py2neo\database.py", line 591, in create
self.update(lambda tx: tx.create(subgraph))
File "D:\python3.8\lib\site-packages\py2neo\database.py", line 445, in update
self._update(cypher, timeout=timeout)
File "D:\python3.8\lib\site-packages\py2neo\database.py", line 467, in _update
tx = self.begin(
File "D:\python3.8\lib\site-packages\py2neo\database.py", line 351, in begin
return Transaction(self, autocommit=False, readonly=readonly,
File "D:\python3.8\lib\site-packages\py2neo\database.py", line 915, in __init__
self._ref = self._connector.begin(self.graph.name, readonly=readonly,
File "D:\python3.8\lib\site-packages\py2neo\client\__init__.py", line 1359, in begin
return cx.begin(graph_name, readonly=readonly,
File "D:\python3.8\lib\site-packages\py2neo\client\http.py", line 200, in begin
location_path = urlsplit(r.headers["Location"]).path
File "D:\python3.8\lib\site-packages\urllib3\_collections.py", line 157, in __getitem__
val = self._container[key.lower()]
KeyError: 'location'
这里是全部代码:
from py2neo import Graph, Node, Relationship, NodeMatcher
graph = Graph('http://127.0.0.1:7474/', name="test", password="12345678")
node1 = Node('Person', name='Bob')
node2 = Node('Person', name='Alice')
node3 = Node('animal', name='cat')
node4 = Node('animal', name='dog')
r1 = Relationship(node2, 'know', node1)
r2 = Relationship(node1, 'know', node3)
r3 = Relationship(node2, 'has', node3)
r4 = Relationship(node2, 'has', node4)
graph.create(node1)
graph.create(node2)
graph.create(node3)
graph.create(node4)
graph.create(r1)
graph.create(r2)
graph.create(r3)
graph.create(r4)
matcher = NodeMatcher(graph)
print(list(matcher.match('animal')))
请告诉我原因,提前谢谢你。
您的代码在我运行时运行良好,因此在调用它时某些东西在您的 neo4j 服务器上不起作用。下面是来自 py2neo http.py ("D:\python3.8\lib\site-packages\py2ne