I'm a newbe with py2neo. Trying to create a KG which includes some nodes like
graph = Graph('http://127.0.0.1:7474/', name="test", password="12345678")
node1 = Node('Person', name='Bob')
graph.create(node1)
but I'm getting a KeyError: 'location', in detail:
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'
Here are the whole codes:
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')))
Please tell me the reason, thank you in advance.
Your code works well when I run it so something is not working on your neo4j server when calling it. Below is the code from py2neo http.py ("D:\python3.8\lib\site-packages\py2neo\client\http.py")
Thus the http response has no header location, and raising an error.
Try using http://localhost:7474/ instead of http://127.0.0.1:7474/.