Enabling debug logs can help troubleshoot connection or driver behaviour while connecting to Aura instances.
This should be considered after engaging with the support team and should not be the first element to bring to your support ticket.
The items to evaluate initially are the environment and/or the configuration is not the source of issues seen.
Debug-level logs can be enabled by including the following lines in your Python code:
import logging
import sys
# create a handler, e.g. to log to stdout
handler = logging.StreamHandler(sys.stdout)
# configure the handler to your liking
handler.setFormatter(logging.Formatter(
"[%(levelname)-8s] %(threadName)s(%(thread)d) %(asctime)s %(message)s"
))
See Logging Levels for a list of levels.
Full working example:
Replace <username> , '<password>' and <dbid> accordingly.
from neo4j import GraphDatabase
import logging
import sys
# create a handler, e.g. to log to stdout
handler = logging.StreamHandler(sys.stdout)
# configure the handler to your liking
handler.setFormatter(logging.Formatter(
"[%(levelname)-8s] %(threadName)s(%(thread)d) %(asctime)s %(message)s"
))
# add the handler to the driver's logger
logging.getLogger("neo4j").addHandler(handler)
# make sure the logger logs on the desired log level
logging.getLogger("neo4j").setLevel(logging.DEBUG)
# from now on, DEBUG logging to stderr is enabled in the driver
creds = ('<username>', '<password>')
uri = 'neo4j+s://<dbid>.databases.neo4j.io:7687'
driver = GraphDatabase.driver(uri,auth=creds)
def get_actors(tx, movie_name): # Define Unit of work
result = tx.run(
"MATCH (p:Person)-[:ACTED_IN]->(m) "
"WHERE toLower(m.title) CONTAINS toLower($title) "
"RETURN DISTINCT p.name as actorsTx",
title=movie_name) # Named parameters
return [record["actorsTx"] for record in result]
try:
with driver.session() as session:
# Run the unit of work within a Read Transaction
actors = session.read_transaction(get_actors, movie_name="matrix")
for actor in actors:
print(f"Found actor: {actor}")
except Exception as e:
print(f"Exception while running read query: {e}")
Comments
0 comments
Please sign in to leave a comment.