2

I'm trying to execute a cypher query with py2neo 2.0 (and Neo4j 2.1.6), but it fails with the following error:

File "C:\Envs\project\lib\site-packages\py2neo\core.py", line 678, in cypher

self.__cypher = CypherResource(metadata["cypher"], metadata.get("transaction")) KeyError: "u'cypher'

While debugging, I found that the metadata property doesn't have a cypher entry, but I'm wondering how I can solve it.

enter image description here

Community
  • 1
  • 1
Daniel Silva
  • 379
  • 1
  • 11

1 Answers1

10

This error can be reproduced when initializing py2neo.Graph with an invalid URI:

>>> from py2neo import Graph
>>> graph = Graph('http://localhost:7474')
>>> test = graph.cypher.execute('MATCH n RETURN n LIMIT 5')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/nicole/Envs/squid/lib/python2.7/site-packages/py2neo/core.py", line 678, in cypher
self.__cypher = CypherResource(metadata["cypher"],     metadata.get("transaction"))
KeyError: u'cypher'

Perhaps Nigel can confirm, but in my experience with py2neo 2.0 you need to initialize with the /db/data/ endpoint:

>>> from py2neo import Graph
>>> graph = Graph('http://localhost:7474/db/data/')
>>> test = graph.cypher.execute('MATCH n RETURN n LIMIT 5')
Nicole White
  • 7,720
  • 29
  • 31
  • 3
    Nicole is correct, the URI must contain `/db/data/`. Note though that an alternative way to create the `Graph` with the base URI is `ServiceRoot('http://localhost:7474').graph`. – Nigel Small Jan 30 '15 at 09:12