Python Error FileNotFoundError: [Errno 2] No such file or directory

Hi everyone, I am running a code found in this book Hands-On Graph Analytics with Neo4j which originally had a missing parentheses (alredy fixed), but still has something wrong

from neo4j import GraphDatabase

URL="bolt://localhost:7687"
USER="neo4j"
PWD="neo4j"

driver = GraphDatabase.driver(URL, auth= (USER, PWD))
query = "MATCH (a:Person {id: 2037491})- [:IS_FRIEND_WITH]-(b:Person) RETURN count(b.id)"
with driver.session() as session:
    with session.begin_transaction() as tx:
        result = tx.run(query)
        summary = result.summary() 
        avail = summary.result_available_after # ms 
        cons = summary.result_consumed_after   # ms 
        total_time = avail + cons 

The bit of the error is the following

And the full screenshot of the error is

Any help will be appreciated

Best regards

Mau

Hi! If you are using Python 3.7.x and Neo4j 4.x, update your driver statement to include encrypted=False:

driver = GraphDatabase.driver(URL, auth= (USER, PWD), encrypted=False)

Here is the relevant page: https://neo4j.com/developer/kb/using-python-with-neo4j-ver4-0/

I hope this helps.

Hi Steve thank you for your help, I did the modification but now I have another error

ServiceUnavailable: Failed to establish connection to ('127.0.0.1', 7687) 
(reason [WinError 10061] Unable to establish a connection as the target
 computer expressly denied that connection)

Here is the screenshoot of the error

Any help will be appreciated

Mau

Unfortunately, I can't help much with this one. I've only seen this message on our server at work. It requires administrator privileges to open the port, which I do not have. If you have sufficient privileges, you might try looking at the link below (I assume you are running Windows, since the message references WinError.)
Hopefully, someone with more experience with this error will post more.

Hi, managed to solve the issue partially by opening the Neo4j Browser and there is no longer errors related to port or I/O stuff.

I guess that the new error is caused to a missing step before the code

Best Regards

Glad you got it working. This new one looks like a Python error. It looks like your query probably is not returning any results since it's saying avail and cons are both None.