gpt4 book ai didi

python - 尝试从python连接到neo4j的AuthError

转载 作者:行者123 更新时间:2023-12-03 20:49:37 30 4
gpt4 key购买 nike

我正在尝试在 docker 容器中运行 neo4j 并从不在容器中运行的 python 脚本连接到它,但我收到了 AuthError。
我正在按照 here 的说明进行操作
启动neo4j

docker run \
--publish=7474:7474 --publish=7687:7687 \
--volume=$HOME/neo4j/data:/data \
--volume=$HOME/neo4j/logs:/logs \
neo4j:3.5
我还使用这些添加的说明完成了此操作“默认情况下,Neo4j 需要身份验证,并要求您在第一次连接时使用 neo4j/neo4j 登录并设置新密码。您可以通过指定 --env 直接为 Docker 容器设置密码NEO4J_AUTH=neo4j/在您的运行指令中。”
启动neo4j
docker run \
--publish=7474:7474 --publish=7687:7687 \
--volume=$HOME/neo4j/data:/data \
--volume=$HOME/neo4j/logs:/logs \
--env NEO4J_AUTH=neo4j/neo \
neo4j:3.5
完成上述任一操作后,我就可以通过 http://localhost:7474/的 Web 界面进行连接
现在我想按照 here 的描述连接一个 python 脚本这让我运行此代码(请注意,我已更改密码以匹配 docker 命令中的 NEO4J_AUTH 设置)。
从 neo4j 导入 GraphDatabase
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", "neo")
greeter.print_greeting("hello, world")
greeter.close()
当我运行此代码时,出现此错误。
Traceback (most recent call last):
File "/Users/j/projects/neotest/neo.py", line 25, in <module>
greeter = HelloWorldExample("bolt://localhost:7687", "neo4j", "neo4j")
File "/Users/j/projects/neotest/neo.py", line 6, in __init__
self.driver = GraphDatabase.driver(uri, auth=(user, password))
File "/usr/local/lib/python3.7/site-packages/neo4j/__init__.py", line 183, in driver
return cls.bolt_driver(parsed.netloc, auth=auth, **config)
File "/usr/local/lib/python3.7/site-packages/neo4j/__init__.py", line 196, in bolt_driver
return BoltDriver.open(target, auth=auth, **config)
File "/usr/local/lib/python3.7/site-packages/neo4j/__init__.py", line 359, in open
pool = BoltPool.open(address, auth=auth, pool_config=pool_config, workspace_config=default_workspace_config)
File "/usr/local/lib/python3.7/site-packages/neo4j/io/__init__.py", line 531, in open
seeds = [pool.acquire() for _ in range(pool_config.init_size)]
File "/usr/local/lib/python3.7/site-packages/neo4j/io/__init__.py", line 531, in <listcomp>
seeds = [pool.acquire() for _ in range(pool_config.init_size)]
File "/usr/local/lib/python3.7/site-packages/neo4j/io/__init__.py", line 545, in acquire
return self._acquire(self.address, timeout)
File "/usr/local/lib/python3.7/site-packages/neo4j/io/__init__.py", line 409, in _acquire
connection = self.opener(address, timeout)
File "/usr/local/lib/python3.7/site-packages/neo4j/io/__init__.py", line 528, in opener
return Bolt.open(addr, auth=auth, timeout=timeout, routing_context=routing_context, **pool_config)
File "/usr/local/lib/python3.7/site-packages/neo4j/io/__init__.py", line 227, in open
raise error
File "/usr/local/lib/python3.7/site-packages/neo4j/io/__init__.py", line 222, in open
connection.hello()
File "/usr/local/lib/python3.7/site-packages/neo4j/io/_bolt3.py", line 148, in hello
self.fetch_all()
File "/usr/local/lib/python3.7/site-packages/neo4j/io/_bolt3.py", line 393, in fetch_all
detail_delta, summary_delta = self.fetch_message()
File "/usr/local/lib/python3.7/site-packages/neo4j/io/_bolt3.py", line 339, in fetch_message
response.on_failure(summary_metadata or {})
File "/usr/local/lib/python3.7/site-packages/neo4j/io/_bolt3.py", line 544, in on_failure
raise AuthError(message)
neo4j.exceptions.AuthError: {code: None} {message: None}

最佳答案

您的错误确实表明代码有点不同:

Traceback (most recent call last):
File "/Users/j/projects/neotest/neo.py", line 25, in <module>
greeter = HelloWorldExample("bolt://localhost:7687", "neo4j", "neo4j")
这里显示您使用密码“neo4j”而不是“neo”启动了 HelloWorldClass

关于python - 尝试从python连接到neo4j的AuthError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63540282/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com