Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)

I am a newbie to neo4j and want to do the connection with Python. I am using neo4j version 3.0.3

I have written the code in Python file, I have also changed the password, since my password is root:

from neo4j.v1 import GraphDatabase, basic_auth

driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth(user = "neo4j", password = "root"))

session = driver.session()

session.run("CREATE (a:Person {name:'Bob'})")

result = session.run("MATCH (a:Person) RETURN a.name AS name")

for record in result:

    print(record["name"])

session.close()

But on running it, I am getting the following errors:

Traceback (most recent call last):

  File "D:/Work/MySQL_neo4j_Importer/dumping_ingredients.py", line 3, in <module>

    session = driver.session()

  File "C:\Python27\lib\site-packages\neo4j\v1\session.py", line 148, in session

    session = Session(self)

  File "C:\Python27\lib\site-packages\neo4j\v1\session.py", line 461, in __init__

    self.connection = connect(driver.host, driver.port, driver.ssl_context, **driver.config)

  File "C:\Python27\lib\site-packages\neo4j\v1\connection.py", line 403, in connect

    s = create_connection((host, port))

  File "C:\Python27\lib\socket.py", line 557, in create_connection

    for res in getaddrinfo(host, port, 0, SOCK_STREAM):

socket.gaierror: [Errno 11004] getaddrinfo failed

1 Answer

0 votes
by (108k points)

If you are working with Neo4j 1.8 / 1.9 / 2.0 / 2.1 / 2.2 / 2.3 you need to use Py2neo which is a client package and comprehensive toolkit for operating with Neo4j from within Python applications and from the command line. The library supports both Bolt and HTTP.  

For the best of career growth, check out Intellipaat’s Python online Course and get certified!

Browse Categories

...