这是我正在运行的脚本:
#Connection
db = MySQLdb.connect(host = "localhost:3306", user = "username", passwd = "password", db = "database", port = 3306)
cursor = db.cursor()
csv_data = csv.reader(file('/home/pi/z_fs/sample_file_for_mysql_upload.csv'))
next(csv_data, None)
for row in csv_data:
cursor.execute('INSERT INTO z_rec_sales(id,address,state,city,zipcode,price,sold_date,price_per_sqft, beds,bathrooms,sqft,url)' \
'VALUES("%s", "%s", "%s","%s", "%s", "%s", "%s","%s", "%s", "%s", "%s")',row)
运行此脚本时,出现错误:
MySQLdb._exceptions.ProgrammingError: not enough arguments for format string
出什么问题了?
答案 0 :(得分:0)
%s说明符的数量与您传递的参数数量不匹配。 您有12个参数,但只有11个'%s'。
答案 1 :(得分:0)
cursor.execute('INSERT INTO z_rec_sales(id,address,state,city,zipcode,price,sold_date,price_per_sqft, beds,bathrooms,sqft,url)' \
'VALUES("%s", "%s", "%s","%s", "%s", "%s", "%s","%s", "%s", "%s", "%s")',row)
%s说明符数量与您传递的参数数量不匹配。