Problems of inputting user data to mysql

def validate_username(self, slot_value: Any, dispatcher: CollectingDispatcher, tracker: Tracker, domain:DomainDict) -> Dict\[Text, Any\]:

    

    name = str(slot_value)

    new = tracker.get_slot('new')

    try:

        connect= mysql.connector.connect(host="localhost",user="root",password="",database="restaurant")



        if connect.is_connected:

            cursor = connect.cursor(dictionary=True)

            query = "SELECT username FROM user WHERE username = %s"

            cursor.execute(query,(name,))

            row = cursor.fetchall()



            if not all(char.isalpha() for char in name):

                dispatcher.utter_message("name should be english")

                return {"username": None}



            elif new:



                if len(row) == 0:

                    return {"username": name}

                else:

                    dispatcher.utter_message("name was used")

                    return {"username": None}

            else:

                if len(row) == 0:

                    dispatcher.utter_message("wrong name, please input again")

                    return {"username": None}

                else:

                    return {"username": name}



            

    except Error as e:

        dispatcher.utter_message("error_checkname")



    return \[\]

here is the part of the class ValidateUserLogin