问题描述
我在这里学习了简单的 py2neo 教程:http://nicolewhite.github.io/neo4j-jupyter/hello-world.html
一切正常,所有条目都出现在 neo4j 浏览器版本中,但是当我尝试运行内联 Cypher 查询时,我收到 404 错误。
%%cypher
http://neo4j:password@localhost:7474/db/data/
MATCH (person:Person)-[:LIKES]->(drink:Drink)
RETURN person.name,drink.name,drink.calories
这是回溯:
Format: (http|https)://username:password@hostname:port/db/name
---------------------------------------------------------------------------
NotFoundError Traceback (most recent call last)
<ipython-input-12-de2d5705ff61> in <module>
----> 1 get_ipython().run_cell_magic('cypher','','http://neo4j:password@localhost:7474/db/data/\nMATCH (person:Person)-[:LIKES]->(drink:Drink)\nRETURN person.name,drink.calories\n')
~/.local/lib/python3.6/site-packages/IPython/core/interactiveshell.py in run_cell_magic(self,magic_name,line,cell)
2369 with self.builtin_trap:
2370 args = (magic_arg_s,cell)
-> 2371 result = fn(*args,**kwargs)
2372 return result
2373
<decorator-gen-127> in execute(self,cell,local_ns)
~/.local/lib/python3.6/site-packages/IPython/core/magic.py in <lambda>(f,*a,**k)
185 # but it's overkill for just that one bit of state.
186 def magic_deco(arg):
--> 187 call = lambda f,**k: f(*a,**k)
188
189 if callable(arg):
<decorator-gen-126> in execute(self,**k)
188
189 if callable(arg):
~/.local/lib/python3.6/site-packages/cypher/magic.py in execute(self,local_ns)
106 user_ns.update(local_ns)
107 parsed = parse("""{0}\n{1}""".format(line,cell),self)
--> 108 conn = Connection.get(parsed['as'] or parsed['uri'],parsed['as'])
109 first_word = parsed['cypher'].split(None,1)[:1]
110 if first_word and first_word[0].lower() == 'persist':
~/.local/lib/python3.6/site-packages/cypher/connection.py in get(cls,descriptor,alias)
45 cls.current = conn
46 else:
---> 47 cls.current = Connection(descriptor,alias)
48 if cls.current:
49 return cls.current
~/.local/lib/python3.6/site-packages/cypher/connection.py in __init__(self,connect_str,alias)
24 gdb = GraphDatabase(self.connections[connect_str])
25 else:
---> 26 gdb = GraphDatabase(connect_str)
27 alias = alias or connect_str
28 except:
~/.local/lib/python3.6/site-packages/neo4jrestclient/client.py in __init__(self,url,username,password,cert_file,key_file)
81 response_json = response.json()
82 else:
---> 83 raise NotFoundError(response.status_code,"Unable get root")
84 if "data" in response_json and "management" in response_json:
85 response = Request(**self._auth).get(response_json["data"])
NotFoundError: Code [404]: Not Found. nothing matches the given URI.
Unable get root
我尝试根据此答案 here 检查 URI 是否有效,但我也收到了 404 错误:
~$ curl -i --user neo4j:password http://localhost:7474/db/data/
HTTP/1.1 404 Not Found
Access-Control-Allow-Origin: *
Cache-Control: must-revalidate,no-cache,no-store
Content-Type: text/html;charset=iso-8859-1
Content-Length: 0
我尝试设置 Graph
选项以包含链接,但没有帮助:
graph = Graph("http://neo4j:password@localhost:7474/db/data/")
你能告诉我我哪里做错了吗?
解决方法
我大部分时间都在使用 py2neo。这是我连接到本地 neo4j 数据库的方式。
from py2neo import Graph
graph = Graph("bolt://localhost:7687",auth=("neo4j","xxxxx"))
try:
graph.run("Match () Return 1 Limit 1")
print('ok')
except Exception:
print('not ok')