MySQLConverter' object has no attribute '_tuple_to_mysql' exception with mysql-connector

允我心安 提交于 2019-12-02 01:13:26

You're wrapping each individual argument within a tuple; don't do that. That is, do this instead:

dbcur.execute(
     """INSERT INTO scripting (URL, Title, Content, Month, Date, Year, Time, TimeZone) 
     VALUES ("%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s")""",
     (URL[i], Title[i], Content[i], Month[i], Date[i], Year[i], Time1[i], TimeZone[i]))

You only need to wrap all substituted values in one tuple, no exceptions.

I can see why you're confused ("URL: url. I set this with tuple and it is fine."): with DBAPI a single value also needs to be wrapped in 1-tuple in the following example), but that is still the same rule applying here:

 dbcur.execute('INSERT INTO scripting (URL) VALUES (%s)', (URL,))

Now we only substitute URL, but we still wrap "all", e.g. that single argument, in one tuple.

Antti Haapala has a great answer but you could also tidy it up by using zip to build the row to insert for you

for row in zip(URL, Title, Content, Month, Date, Year, Time1, TimeZone):
    dbcur.execute(
        """INSERT INTO scripting (URL, Title, Content, Month, Date, Year, Time, TimeZone)
           VALUES ("%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s")""",
           row)
    dbcon.commit()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!