Python neo4j:无法连接到DB[py2neo]

Python neo4j:无法连接到DB[py2neo],python,neo4j,py2neo,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()

我试图通过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

确保您已经安装了pip,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()
问题解决了。 我发现在my/etc/hosts上没有定义localhost。。。。。
我刚加入一家新公司,买了一台新的mac电脑。不知道为什么默认情况下没有放置127.0.0.1 localhost…

是的。我已经在我的mac上安装了pip和Neo4j。我可以使用浏览器登录到。但是,我仍然无法通过py2neo连接到Neo4j……它也可以这样传递:graph=graph(user=“Neo4j”,password=“yourpassword”),您忘记了逗号,编辑队列已满