Я получаю эту ошибку при запуске моего python кода, в который я хотел вставить данные из CSV-файла в mysql ...
Traceback (most recent call last):
File "./mongo2sql.py", line 16, in <module>
mycursor.execute(drop, ctbl)
File "/usr/local/lib64/python3.6/site-packages/mysql/connector/cursor_cext.py", line 248, in execute
prepared = self._cnx.prepare_for_mysql(params)
File "/usr/local/lib64/python3.6/site-packages/mysql/connector/connection_cext.py", line 632, in prepare_for_mysql
raise ValueError("Could not process parameters")
ValueError: Could not process parameters
Вот мой код py:
#!/usr/bin/python3
import mysql.connector
mydb = mysql.connector.connect(
host="host",
user="user",
passwd="user",
database="db"
)
mycursor = mydb.cursor()
drop = "Drop Table User;"
ctbl = "Create Table db.User (`_id` VARCHAR(255) not null primary key,`accountStatus` VARCHAR(255) null,`active` BOOL null,`allowedPartners` VARCHAR(255) null,`allowedProviders` VARCHAR(255) null,`capabilities` VARCHAR(255) null,`createdDateTime` DATETIME null,`firstName` VARCHAR(255) null,`lastName` VARCHAR(255) null,`mail` VARCHAR(255) null,`role` VARCHAR(255) null,`sourcePartnerId` VARCHAR(255) null)"
mycursor.execute(drop, ctbl)
mydb.commit()
print("Table Dropped & New created \n Working on inserting data...")
sql = "INSERT INTO vdmUser (_id,accountStatus,active,allowedPartners,allowedProviders,capabilities,createdDateTime,firstName,lastName,mail,role,sourcePartnerId) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,)"
with open("userlist.csv", "r") as a_file:
for line in a_file:
stripped_line = line.strip()
print(stripped_line)
mycursor.execute(sql,stripped_line)
mydb.commit()
print(mycursor.rowcount, "record inserted.")
Я немного новичок в python, поэтому любые рекомендации будут оценены.