Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to connect NEO4J using neo4j python driver

I'm unable to connect to Neo4j using neo4j-python-driver version 5.3.0. Requirement is using Neo4j python driver to query NEO4J DB using cypher queries. It gives the error failed to connect to server even when the database is up and running and i can able to login and use through NEO4J Desktop. Getting below error

neo4j.exceptions.ServiceUnavailable: Couldn't connect to <URI>:7687 (resolved to ()):
[SSLCertVerificationError] Connection Failed. Please ensure that your database is listening on the correct host and port and that you have enabled encryption if required. Note that the default encryption setting has changed in Neo4j 4.0. See the docs for more information. Failed to establish encrypted connection. (code 1: Operation not permitted)

Note : URI hided in the above error.

I have added the exception to Ignores certificate verification issue, but it won't solve the issue.

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

Appreciate your help to resolve the issue.

i'm connecting via below snippet

from neo4j import GraphDatabase
import urllib3

#Ignores certificate verification issue
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)


# Initialize connection to database
driver = GraphDatabase.driver('bolt+s://<URI>:7687', auth=(',username', '<password'))


query = 'match (n:Event{name:"test"}) return n'

#Run Cypher query
with driver.session() as session:
    info = session.run(query)
    for item in info:
        print(item)
like image 851
Tono Kuriakose Avatar asked Oct 27 '25 15:10

Tono Kuriakose


2 Answers

If your Neo4j is running as a Docker container, try using the container name instead of localhost. In my case, it helped to resolve the issue.

from neo4j import GraphDatabase

AUTH = ("neo4j", "password")
# neo4j is the container name
URI = "neo4j://neo4j:7687"

with GraphDatabase.driver(URI, auth=AUTH) as driver:
    driver.verify_connectivity()
    print("Working")
like image 158
Karen Avatar answered Oct 29 '25 05:10

Karen


No way to know how you are connecting, but we do:

from neo4j import GraphDatabase
address="bolt://localhost:7687"
auth=('neo4j', "password")
driver = GraphDatabase.driver(address, auth=auth, encrypted=False)
....
like image 38
Gonzalo Odiard Avatar answered Oct 29 '25 03:10

Gonzalo Odiard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!