【问题标题】:py2neo: using cypher inline gives 404 errorpy2neo:使用 cypher inline 会产生 404 错误
【发布时间】:2021-03-22 06:13:48
【问题描述】:

我在这里学习简单的 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.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, line, 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, *a, **k: f(*a, **k)
    188 
    189         if callable(arg):

<decorator-gen-126> in execute(self, line, 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, *a, **k: f(*a, **k)
    188 
    189         if callable(arg):

~/.local/lib/python3.6/site-packages/cypher/magic.py in execute(self, line, cell, 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

我尝试检查 URI 是否根据此答案 here 工作,我也收到 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/")

你能告诉我我哪里做错了吗?

【问题讨论】:

  • 教程很可能已经过时了。你用的是什么版本的 Neo4j?
  • 这是最新的,4.2.4

标签: python neo4j py2neo


【解决方案1】:

我大部分时间都在使用 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')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-04
    • 2019-04-15
    • 2016-08-12
    • 2011-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多