TypeError: not all arguments converted during string formatting Error in tuple python

前端 未结 2 1090
旧巷少年郎
旧巷少年郎 2021-01-24 09:20

Im trying to save bunch of tuples in DB

 cursor = cnx.cursor()
         query = \"\"\"INSERT INTO `TableA`
                     (`clientid`,
                             


        
2条回答
  •  無奈伤痛
    2021-01-24 10:05

    Here is a minimal example that I got working.

    query = "INSERT INTO `pet`(`name`,`owner`) values(%s,%s)"
    listTosave = [('some','shsjhs'),('sosos','shshsh')]
    cursor.executemany(query, listTosave)
    

    Make sure that you have a list of tuples, and that you use %s in query string

提交回复
热议问题