Windows桌面的py2neo和Neo4j无法连接

时间:2019-05-07 20:44:33

标签: python database neo4j graph-databases py2neo

我总是会收到此错误:

  File "test.py", line 13, in <module>
    graph.create(alice_knows_bob)
  File "C:\Python27\lib\site-packages\py2neo\database.py", line 355, in create
    with self.begin() as tx:
  File "C:\Python27\lib\site-packages\py2neo\database.py", line 346, in begin
    return Transaction(self, autocommit)
  File "C:\Python27\lib\site-packages\py2neo\database.py", line 758, in __init__
    self.transaction = self.connector.begin()
  File "C:\Python27\lib\site-packages\py2neo\internal\connectors.py", line 290, in begin
    tx = self.pool.acquire()
  File "C:\Python27\lib\site-packages\neobolt\direct.py", line 704, in acquire
    return self.acquire_direct(self.address)
  File "C:\Python27\lib\site-packages\neobolt\direct.py", line 597, in acquire_direct
    connection = self.connector(address, error_handler=self.connection_error_handler)
  File "C:\Python27\lib\site-packages\py2neo\internal\connectors.py", line 225, in connector
    return connect(address_, auth=cx_data["auth"], **kwargs)
  File "C:\Python27\lib\site-packages\neobolt\direct.py", line 960, in connect
    raise last_error
neobolt.exceptions.AuthError: The client is unauthorized due to authentication failure.

我尝试这样连接:

from py2neo import Graph
graph = Graph()

remote_graph = Graph("bolt://neo4j:neo4j@localhost:7687/db/data/")

我不确定在哪里可以找到我的真实用户名和密码。还是我验证不正确?

1 个答案:

答案 0 :(得分:0)

我找到了答案!

首先,请确保打开http://localhost:7474/browser/并输入用户名neo4j和您在创建图形时设置的密码。如果您可以登录,那么您拥有正确的用户名和密码。

接下来,请确保您安装了py2neo 2.0.8版。较新的版本在某种程度上存在身份验证问题。

然后使用此代码进行身份验证:

from py2neo import Graph, authenticate
graph = Graph()
# Authenticate the user using py2neo.authentication

authenticate("localhost:7474", "neo4j", "<pass>")

# # Connect to Graph and get the instance of Graph

remote_graph = Graph("http://localhost:7474/db/data/")