'Python update data with pymsql

Hi when I update data with sql, I get a string error. Please help me.

This is my error:

TypeError: not enough arguments for format stringimport pymysql.connect string error

My code is as follows:

db = mysql.connector.connect(user='root', password='1234', host='localhost', database='sosyalbe')
cursor = db.cursor()
cursor.execute("SELECT * FROM siparisler WHERE siparis_durum ='İptal'")

order = cursor.fetchone()
id = order[0]

dss = 10
cursor.execute("UPDATE siparisler SET urun_baslangic = '%s' WHERE order_id ='%s'" %dss % id)  #errror

cursor.execute("UPDATE siparisler SET urun_baslangic = (?) WHERE id = (?)" (dss, id))   #ERROR

please help !



Solution 1:[1]

You're missing a comma between the string and tuple of arguments. Also, note that the %ss should not be surrounded with quotes, as they are not string literals:

cursor.execute("UPDATE siparisler SET urun_baslangic = %s WHERE order_id = %s", (dss, id))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1