neo4j:无法连接到DB [py2neo]

时间:2018-01-10 02:16:21

标签: python neo4j py2neo

我试图通过py2neo连接neo4j。但是有些错误说主机名或节点名称没有找到...... 我尝试了下面的代码连接,但都没有工作

graph = Graph()

#graph = Graph("http://username:password@localhost:7474/db/data/")

但是,我可以使用浏览器连接到带凭据的URL。

以下是我收到的错误消息。有人可以帮我这个吗?

File "test.py", line 56, in main
    graph = Graph()
  File "/anaconda2/lib/python2.7/site-packages/py2neo/database/__init__.py", line 327, in __new__
    use_bolt = version_tuple(inst.__remote__.get().content["neo4j_version"]) >= (3,)
  File "/anaconda2/lib/python2.7/site-packages/py2neo/database/http.py", line 154, in get
    response = self.__base.get(headers=headers, redirect_limit=redirect_limit, **kwargs)
  File "/anaconda2/lib/python2.7/site-packages/py2neo/packages/httpstream/http.py", line 966, in get
    return self.__get_or_head("GET", if_modified_since, headers, redirect_limit, **kwargs)
  File "/anaconda2/lib/python2.7/site-packages/py2neo/packages/httpstream/http.py", line 943, in __get_or_head
    return rq.submit(redirect_limit=redirect_limit, **kwargs)
  File "/anaconda2/lib/python2.7/site-packages/py2neo/packages/httpstream/http.py", line 433, in submit
    http, rs = submit(self.method, uri, self.body, self.headers)
  File "/anaconda2/lib/python2.7/site-packages/py2neo/packages/httpstream/http.py", line 342, in submit
    raise NetworkAddressError(err.args[1], host_port=uri.host_port)
py2neo.packages.httpstream.http.NetworkAddressError: nodename nor servname provided, or not known: localhost:7474

2 个答案:

答案 0 :(得分:0)

确保您已安装了点子,Neo4j正在您的计算机上运行并且您已提供正确的登录凭据。

这就是我在Jupyter笔记本中使用Py2neo的方法。

#Installing Py2Neo: Takes more than 30 seconds
!pip install py2neo

from py2neo import Graph, Node, Relationship
# Connecting Neo4j: Have to make sure Neo4j Community Edition or Ne4j Desktop is running
# It can be passed like this as well: graph = Graph(user="neo4j" password="yourpassword")
graph = Graph()

答案 1 :(得分:0)

问题解决了。 我发现我的/ etc / hosts中没有定义localhost ..... 我刚刚加入一家新公司并获得了一台新的mac。不知道为什么默认情况下它没有放置127.0.0.1 localhost .....