MySQLdb TypeError: %d format: a number is required

required, not str问题解决

mactanxin 2012-03-23 16:59:46
遇到问题: TypeError: %d format: a number is required, not str
解决办法: 传给sql的变量写对格式就行了. sql里不需要对对应的变量写%d,只写%s就可以了

遇到问题: (1146, "Table 'database.'table_name'' doesn't exist")
解决办法: 不用cursur.execute(sql,param)方式,改成拼串方式写. str写成 column = '%s' , int写成 column = %s. 所有的int不需要加单引号. str需要单引号

sql = "insert into loganalyzer(timespan, id, action, action_num)values(%s,%s,%s,%s)"
for anchor in anchorLogList:
    action = anchor["actions"]
    nowTime = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))

    data=(nowTime, anchor["userId"], "playTime", action["playTime"])
    bufferData.append(data)
    number=number+1
    if number>100:
        cursor.executemany(sql,bufferData)
        db.commit()
        number=0
        bufferData=[]
if number > 0:
    cursor.executemany(sql,bufferData)
    db.commit()






你可能感兴趣的:(MySQLdb TypeError: %d format: a number is required)