2014-03-03 55 views
0
import mysql.connector 
import sys 
from PIL import Image 
import base64 
import cStringIO 
import PIL.Image 

db = mysql.connector.connect(user='root', password='abhi', 
           host='localhost', 
           database='cbir') 
sql = 'INSERT INTO fgh(id,name) VALUES(%d,%s)'  
args = (1,'abhi') 
cursor=db.cursor() 
cursor.execute(sql,args) 
db.commit() 
db.close() 

錯誤的表:值插入使用python

Traceback (most recent call last): 
    File "C:\Users\Abhi\Desktop\cbir-p\New folder\co.py", line 16, in <module> 
    cursor.execute(sql,args) 
    File "C:\Python27\lib\site-packages\mysql\connector\cursor.py", line 472, in execute 
    "Wrong number of arguments during string formatting") 
ProgrammingError: Wrong number of arguments during string formatting 

幫我解決這個錯誤

回答

1

我相信,所有的MySQL參數標記應該是%s。嘗試用%s替換%d,然後查看是否修復了該問題。