Exception when writing transactions in Neo4j python driver: "neo4j.exceptions.AuthError: {code: None} {message: None}"
Exception when writing transactions in Neo4j python driver: "neo4j.exceptions.AuthError: {code: None} {message: None}"
我正在尝试 运行 文档中提到的示例 - https://neo4j.com/developer/python/#_resources
class HelloWorldExample:
def __init__(self, uri, user, password):
self.driver = GraphDatabase.driver(uri, auth=(user, password))
def close(self):
self.driver.close()
def print_greeting(self, message):
with self.driver.session() as session:
greeting = session.write_transaction(self._create_and_return_greeting, message)
print(greeting)
@staticmethod
def _create_and_return_greeting(tx, message):
result = tx.run("CREATE (a:Greeting) "
"SET a.message = $message "
"RETURN a.message + ', from node ' + id(a)", message=message)
return result.single()[0]
if __name__ == "__main__":
greeter = HelloWorldExample("bolt://localhost:7687", "neo4j", "password")
greeter.print_greeting("hello, world")
greeter.close()
错误是-
Traceback (most recent call last):
File "createneodb.py", line 26, in <module>
greeter.print_greeting("hello, world")
File "createneodb.py", line 13, in print_greeting
greeting = session.write_transaction(self._create_and_return_greeting, message)
File "C:\Users\omras\AppData\Local\Programs\Python\Python37\lib\site-packages\neo4j\work\simple.py", line 435, in write_transaction
return self._run_transaction(WRITE_ACCESS, transaction_function, *args, **kwargs)
File "C:\Users\omras\AppData\Local\Programs\Python\Python37\lib\site-packages\neo4j\work\simple.py", line 336, in _run_transaction
self._open_transaction(access_mode=access_mode, database=self._config.database, metadata=metadata, timeout=timeout)
File "C:\Users\omras\AppData\Local\Programs\Python\Python37\lib\site-packages\neo4j\work\simple.py", line 271, in _open_transaction
self._connect(access_mode=access_mode, database=database)
File "C:\Users\omras\AppData\Local\Programs\Python\Python37\lib\site-packages\neo4j\work\simple.py", line 122, in _connect
bookmarks=self._bookmarks
File "C:\Users\omras\AppData\Local\Programs\Python\Python37\lib\site-packages\neo4j\io\__init__.py", line 805, in acquire
return self._acquire(self.address, timeout)
File "C:\Users\omras\AppData\Local\Programs\Python\Python37\lib\site-packages\neo4j\io\__init__.py", line 660, in _acquire
connection = self.opener(address, timeout)
File "C:\Users\omras\AppData\Local\Programs\Python\Python37\lib\site-packages\neo4j\io\__init__.py", line 789, in opener
**pool_config
File "C:\Users\omras\AppData\Local\Programs\Python\Python37\lib\site-packages\neo4j\io\__init__.py", line 340, in open
connection.hello()
File "C:\Users\omras\AppData\Local\Programs\Python\Python37\lib\site-packages\neo4j\io\_bolt4.py", line 98, in hello
self.fetch_all()
File "C:\Users\omras\AppData\Local\Programs\Python\Python37\lib\site-packages\neo4j\io\__init__.py", line 517, in fetch_all
detail_delta, summary_delta = self.fetch_message()
File "C:\Users\omras\AppData\Local\Programs\Python\Python37\lib\site-packages\neo4j\io\_bolt4.py", line 271, in fetch_message
response.on_failure(summary_metadata or {})
File "C:\Users\omras\AppData\Local\Programs\Python\Python37\lib\site-packages\neo4j\io\_common.py", line 202, in on_failure
raise AuthError(message)
neo4j.exceptions.AuthError: {code: None} {message: None}
详情:
驱动程序对象和会话对象已成功初始化。然而,问题出在调用 write_transaction 时。我无法理解问题的根源。
我最近遇到了这个错误,最终原因是我的 username/password 出了问题。我在引用的配置文件中把它们弄错了。这令人困惑,因为错误直到我调用 .run()
方法的那一行才出现,即使我在代码的前面建立了会话。
以下是部分答案 — 最初可以设置您的密码,但您可能无法更改它。
- 要从命令行初始设置密码,运行
sudo /usr/bin/neo4j-admin set-initial-password YOUR_PASSWORD_HERE
。
- 或者,您可以 运行 对 neo4j 服务器的 curl 请求,如 here 所述。
- 如果您已经设置了密码,您可能需要删除 auth.ini 文件(关于 here 的更多信息)。
- 使用
sudo neo4j restart
重新启动服务器,这样它就会接受您的新密码。在 debian 上,如果你不使用 sudo,它就会超时。
就个人而言,我可以设置密码,但现在无法更改。我不确定这是否是一个错误,但命令行和 curl 重置方法都报告成功而无需更改密码,即使在重新启动后也是如此。
我正在尝试 运行 文档中提到的示例 - https://neo4j.com/developer/python/#_resources
class HelloWorldExample:
def __init__(self, uri, user, password):
self.driver = GraphDatabase.driver(uri, auth=(user, password))
def close(self):
self.driver.close()
def print_greeting(self, message):
with self.driver.session() as session:
greeting = session.write_transaction(self._create_and_return_greeting, message)
print(greeting)
@staticmethod
def _create_and_return_greeting(tx, message):
result = tx.run("CREATE (a:Greeting) "
"SET a.message = $message "
"RETURN a.message + ', from node ' + id(a)", message=message)
return result.single()[0]
if __name__ == "__main__":
greeter = HelloWorldExample("bolt://localhost:7687", "neo4j", "password")
greeter.print_greeting("hello, world")
greeter.close()
错误是-
Traceback (most recent call last):
File "createneodb.py", line 26, in <module>
greeter.print_greeting("hello, world")
File "createneodb.py", line 13, in print_greeting
greeting = session.write_transaction(self._create_and_return_greeting, message)
File "C:\Users\omras\AppData\Local\Programs\Python\Python37\lib\site-packages\neo4j\work\simple.py", line 435, in write_transaction
return self._run_transaction(WRITE_ACCESS, transaction_function, *args, **kwargs)
File "C:\Users\omras\AppData\Local\Programs\Python\Python37\lib\site-packages\neo4j\work\simple.py", line 336, in _run_transaction
self._open_transaction(access_mode=access_mode, database=self._config.database, metadata=metadata, timeout=timeout)
File "C:\Users\omras\AppData\Local\Programs\Python\Python37\lib\site-packages\neo4j\work\simple.py", line 271, in _open_transaction
self._connect(access_mode=access_mode, database=database)
File "C:\Users\omras\AppData\Local\Programs\Python\Python37\lib\site-packages\neo4j\work\simple.py", line 122, in _connect
bookmarks=self._bookmarks
File "C:\Users\omras\AppData\Local\Programs\Python\Python37\lib\site-packages\neo4j\io\__init__.py", line 805, in acquire
return self._acquire(self.address, timeout)
File "C:\Users\omras\AppData\Local\Programs\Python\Python37\lib\site-packages\neo4j\io\__init__.py", line 660, in _acquire
connection = self.opener(address, timeout)
File "C:\Users\omras\AppData\Local\Programs\Python\Python37\lib\site-packages\neo4j\io\__init__.py", line 789, in opener
**pool_config
File "C:\Users\omras\AppData\Local\Programs\Python\Python37\lib\site-packages\neo4j\io\__init__.py", line 340, in open
connection.hello()
File "C:\Users\omras\AppData\Local\Programs\Python\Python37\lib\site-packages\neo4j\io\_bolt4.py", line 98, in hello
self.fetch_all()
File "C:\Users\omras\AppData\Local\Programs\Python\Python37\lib\site-packages\neo4j\io\__init__.py", line 517, in fetch_all
detail_delta, summary_delta = self.fetch_message()
File "C:\Users\omras\AppData\Local\Programs\Python\Python37\lib\site-packages\neo4j\io\_bolt4.py", line 271, in fetch_message
response.on_failure(summary_metadata or {})
File "C:\Users\omras\AppData\Local\Programs\Python\Python37\lib\site-packages\neo4j\io\_common.py", line 202, in on_failure
raise AuthError(message)
neo4j.exceptions.AuthError: {code: None} {message: None}
详情:
驱动程序对象和会话对象已成功初始化。然而,问题出在调用 write_transaction 时。我无法理解问题的根源。
我最近遇到了这个错误,最终原因是我的 username/password 出了问题。我在引用的配置文件中把它们弄错了。这令人困惑,因为错误直到我调用 .run()
方法的那一行才出现,即使我在代码的前面建立了会话。
以下是部分答案 — 最初可以设置您的密码,但您可能无法更改它。
- 要从命令行初始设置密码,运行
sudo /usr/bin/neo4j-admin set-initial-password YOUR_PASSWORD_HERE
。 - 或者,您可以 运行 对 neo4j 服务器的 curl 请求,如 here 所述。
- 如果您已经设置了密码,您可能需要删除 auth.ini 文件(关于 here 的更多信息)。
- 使用
sudo neo4j restart
重新启动服务器,这样它就会接受您的新密码。在 debian 上,如果你不使用 sudo,它就会超时。
就个人而言,我可以设置密码,但现在无法更改。我不确定这是否是一个错误,但命令行和 curl 重置方法都报告成功而无需更改密码,即使在重新启动后也是如此。