为了账号安全,请及时绑定邮箱和手机立即绑定

pymysql没插入成功也没报错cursor.execute

pymysql没插入成功也没报错cursor.execute

莫回无 2018-08-02 20:50:58
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))是执行失败了么,执行结果:D:\ProgramData\************\python.exe E:/*******/project/test/test.py插入中... 失败了啊 插入中... 失败了啊 插入中...明显是try失败了,然后就print('失败了啊')重新捕获的异常是:not all arguments converted during string formatting是不是因为我插入的是列表不是字符串?
查看完整描述

1 回答

?
Qyouu

TA贡献1786条经验 获得超11个赞

Python 3 字符串格式化 不是 "%s-%s" % (1,2)这么玩吗 .. 我看好多人用逗号隔开就完事了..
Python3 字符串格式化不可以使用列表进行字符串格式化,一个list只能格式化一个位置

可以的话建议你看看cons的值,我看你cons外面又套一个括号.. 变成元组了, 建议排查 待格式化数据


查看完整回答
反对 回复 2018-08-04
  • 1 回答
  • 0 关注
  • 2234 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信