在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Python/ pymysql沒插入成功也沒報錯cursor.execute

pymysql沒插入成功也沒報錯cursor.execute

def save_db(cons):
    db = pymysql.connect(host = '127.0.0.1' , user = 'root' , password = 'root' , port = 3306)
    cursor = db.cursor()
    sql = 'INSERT INTO quote(jy_time,open_price,high_price,low_price,over_price,zhangdiee,zhangdief,chengjiaol,chengjiaoj,zhenfu,huanshoul) VALUE (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'
    print('插入中...')
    try:
        cursor.execute(sql,(cons))
        print(cons)
        db.commit()
    except:
        print('失敗了啊')
        db.rollback()
    db.close()

代碼如上,cursor.execute(sql,(cons))是執(zhí)行失敗了么,執(zhí)行結(jié)果:

D:\ProgramData\************\python.exe E:/*******/project/test/test.py
插入中...
失敗了啊
插入中...
失敗了啊
插入中...

明顯是try失敗了,然后就print('失敗了啊')

重新捕獲的異常是:not all arguments converted during string formatting

是不是因為我插入的是列表不是字符串?

回答
編輯回答
氕氘氚

Python 3 字符串格式化 不是 "%s-%s" % (1,2)這么玩嗎 .. 我看好多人用逗號隔開就完事了..
Python3 字符串格式化不可以使用列表進行字符串格式化,一個list只能格式化一個位置

可以的話建議你看看cons的值,我看你cons外面又套一個括號.. 變成元組了, 建議排查 待格式化數(shù)據(jù)

2017年12月15日 03:43