[Python] Why did it fail when trying to connect to a Neo4j database in Python using...

Discussão em 'Python' iniciado por Stack, Dezembro 22, 2024.

  1. Stack

    Stack Membro Participativo

    I wrote a simple Python script to connect to my Neo4j database instance and retrieve some data using the official Neo4j library. I am trying to run this script on PythonAnywhere, but it failed to connect to the database, printing "Unable to retrieve routing information." The URI, username, and password are correct; it successfully connects to the database from my desktop application written in Java. Here is the full script in 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()


    I tried neo4j://, neo4j+ssc, and bolt, but it did not work.

    Continue reading...

Compartilhe esta Página