Python ';str';对象不可调用到SQL数据库

Python ';str';对象不可调用到SQL数据库,python,Python,我试图通过Python将详细信息输入SQL数据库。我已经创建了带有customerID、firstname、姓氏、town和telephone字段的数据库 当运行这个函数时,我得到一个错误“str”对象对于我试图插入变量值的行是不可调用的 import sqlite3 #function used to add a new customer, once confirmed save the customer in a #customer list def add_customer():

我试图通过Python将详细信息输入SQL数据库。我已经创建了带有customerID、firstname、姓氏、town和telephone字段的数据库

当运行这个函数时,我得到一个错误“str”对象对于我试图插入变量值的行是不可调用的

import sqlite3
#function used to add a new customer, once confirmed save the customer in a 
#customer list
def add_customer():

    #open up the clients database
    new_db = sqlite3.connect('clients.db')

    #create a new cursor object to be able to use the database
    c = clients_db.cursor()
    print("Add customer")
    firstname = ""
    while len(firstname) == 0:
        firstname = input("Enter the customer's first name: ")
    surname = ""
    while len(surname) == 0:
        surname = input("Enter the customer's surname:  ")
    town = ""
    while len(town) == 0:
        town=input("Enter the customer's town: ")
    telephone = '1'
    while len(telephone) != 11:
        while telephone[0] != '0':
            telephone = input("Please enter the customer's telephone number: ")
            if telephone[0] != '0':
                print ("telephone numbers must begin with zero")
            elif len(telephone) != 11:
                print("must have 11 numbers")

    #check that data has been entered
    print(firstname,surname,town,telephone)



    #insert data into the customer table
    c.execute('INSERT INTO Customer VALUES (NULL, ?,?,?,?,)'(firstname, surname, town, telephone))

    print("Customer added successfully ...")

    clients_db.commit()
    clients_db.close()

    if choice ==1:
        another = input("Would you like to add another? yes [y]  or no [n] --> ")
        if another=='y':
            add_customer()
        else:
            main_menu()

SQL语句字符串和参数之间忘记了逗号:

c.execute('INSERT INTO Customer VALUES (NULL, ?,?,?,?,)'(firstname, surname, town, telephone))
#                                                       ^
因此,您可以有效地执行以下操作:
“某个字符串”(arg1、arg2等)
,尝试将该字符串视为函数

只需在此处插入逗号:

c.execute(
    'INSERT INTO Customer VALUES (NULL, ?,?,?,?,)',
    (firstname, surname, town, telephone))
在请求错误帮助时,请包含完整的回溯,以免让我们猜测错误发生在哪里。