cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Adding the Driver in Building Neo4j Applications with Python

I'm trying to do the 'Adding the Driver' Challenge from Building Neo4j Applications with Python using windows and I am struggling. I have followed all the steps and I was able to setup a virtual sandbox environment. I made the following changes to neo4j.py to allow it to connect to the database:

def init_driver(uri, username, password)
    # TODO: Create an instance of the driver here
    current_app.driver = GraphDatabase.driver("bolt://44.201.119.146:7687", auth=("neo4j", "attesting-strand-cannon"))

    #Verify Connectivity
    current_app.driver.verify_connectivity()
    return current_app.driver
    # end::initDriver[]

However, when i run FLASK it shows invalid syntax. When I click get help and I try to do git checkout 01-connect-to-neo4j, I can't see anything. I'm not sure what I am missing.

From what I can understand, the init_driver function is being defined in neo4j.py and is taking in the uri, username and password. This should be called in another file where these variables are passed (and so defining it like i have in neo4j.py is wrong). But I don't know if this is what is required by the challenge. Also, the test file is also defining functions. Do these need to be called from another python code?

Overall, I am feeling very confused!

5 REPLIES 5

anthapu
Graph Fellow

Can you please provide the exact error you are seeing?

I do not see any error in creating driver

Here is a screenshot

3X_5_a_5a734ecd5a8c0fbd6f2b8b6b03753860d33213e8.png

You are missing a separator (:) for function definition. Please take a look at python documentation on defining functions.

def init_driver(uri, username, password):
    # TODO: Create an instance of the driver here
    current_app.driver = GraphDatabase.driver("bolt://44.201.119.146:7687", auth=("neo4j", "attesting-strand-cannon"))

    #Verify Connectivity
    current_app.driver.verify_connectivity()
    return current_app.driver
    # end::initDriver[]

Thanks, I fixed it and now I am getting another error.

To explain the directory structure: the neo4j.py and init.py files are in the folder F:\app-python\api

I have made a new file here called myfile.py with the following code:

import __init__
__init__.create_app()

What I expect it to do is to call the create_app() from init.py which calls the init_driver(uri, username, password) from neo4j.py (containing the code from the top of this thread). I expect it to connect to the database.

But I am getting this:

3X_f_0_f076e16a3f00d55e5ea7b2d599508be1f59bde1d.png

A quick fix for this is to add the -m flag (python -m myfile.py), or there is a stackOverflow thread here which should help you.