为什么尝试使用 PythonAnywhere 连接到 Python 中的 Neo4j 数据库时失败?

问题描述 投票:0回答:1

我编写了一个简单的 Python 脚本来连接到 Neo4j 数据库实例并使用官方 Neo4j 库检索一些数据。我尝试在 PythonAnywhere 上运行此脚本,但它无法连接到数据库,打印“无法检索路由信息”。 URI、用户名和密码正确;它成功地从我用 Java 编写的桌面应用程序连接到数据库。 这是 Python 中的完整脚本:

from neo4j import GraphDatabase


URI = "neo4j+s://uri:7687"
AUTH = ("usn", "pwd")

class PlayersNeo4jDatabaseManager:
    def __init__(self):
        try:
            self.driver = GraphDatabase.driver(URI, auth=AUTH)
        except Exception as ex:
            print(ex)

    def close(self):
        self.driver.close()

    def get_players_query(self, tx):
        query = "MATCH (p:Player) RETURN p LIMIT 1;"
        players = tx.run(query)
        for player in players:
            print(player)

    def get_players(self):
        with self.driver.session(database="neo4j") as session:
            session.read_transaction(self.get_players_query)

playersNeo4jDatabaseManager = PlayersNeo4jDatabaseManager()
playersNeo4jDatabaseManager.get_players()

我尝试了neo4j://、neo4j+ssc和bolt,但没有成功。

python java neo4j scheduled-tasks neo4jclient
1个回答
0
投票

由于网络限制或防火墙设置阻止连接,与 PythonAnywhere 上的 Neo4j 数据库的连接可能会失败。 PythonAnywhere 通常不允许与数据库等外部服务的出站连接。要解决此问题,请确保可以通过公共 IP 访问 Neo4j 实例,并相应地配置 PythonAnywhere 的出站连接设置。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.