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

后端 未结 3 635
孤独总比滥情好
孤独总比滥情好 2021-01-23 03:56

I have 8 kinds of data that I would like to insert into a mysql table through mysql-connector using python. I have looked at some documents saying that it is better to use

3条回答
  •  我在风中等你
    2021-01-23 04:36

    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.

提交回复
热议问题