how to write to firebase real time data base in python using authenticated users?

This is the basic function to push the data to a real time firebase database i want to edit:

def pushUserData2Firebase():

Accept already known user info:

    email = input("Please Enter your email: \n")
    password = getpass("Please Enter your password: \n")

Authenticate and login:

    #Get a reference to auth service
    auth = firebase.auth()
    user = auth.sign_in_with_email_and_password(email, password)

Open a database and push to it:

    # Get a reference to the database service
    db = firebase.database()
    # data to save
    data = {
        "device": "plant monitor 1"
        }
    user = auth.refresh(user['refreshToken'])
    # Pass the user's idToken to the push method
    results = db.child("users").push(data, user['idToken'])
    print("Data pushed succesfully!")

The programs doesn't push anything to the real time database. I read something about service account and admin SDK, but don't know what to change in my code.