python3使用pymysql模块往mysql插入数据时报错

python3使用pymysql模块往mysql插入数据时报错,具体见图片(<class'TypeError'>,TypeError("abytes-likeobject... python3使用pymysql模块往mysql插入数据时报错,具体见图片(<class 'TypeError'>, TypeError("a bytes-like object is required, not 'int'",))脚本如下,求大神指点迷津!#!/home/nbpmts/usr/local/python3/bin/python3#-*-coding:utf-8-*-import pymysql,timedate=time.strftime("%Y%m%d")lastday="3.7053216E15"db = pymysql.connect(host='xxxx',port=xxxx,user='xxxx',passwd='xxxx',db='xxxx',charset='utf8')cursor = db.cursor()#备份sqlsql1=("create table cd_quotation_data_%s as select * from cd_quotation_data;" %date)sql2=("create table st_commodity_settleprice_%s as select * from st_commodity_settleprice;" %date)#删除sqlsql3="delete from cd_quotation_data where tradedate = (select TRADEDATE from sd_market_info);"sql4="delete from st_commodity_settleprice where tradedate = (select TRADEDATE from sd_market_info);"#插入sqlsql5=("""insert into cd_quotation_data(ID,TRADEDATE,MEMBERID,COMMODITYID,OPENPRICEBUY,OPENPRICESELL,OPENTIME,CLOSEPRICEBUY,CLOSEPRICESELL,CLOSETIME,HIGHBUYPRICE,LOWBUYPRICE,HIGHSELLPRICE,LOWSELLPRICE,QUOTETIME,PRECBUYPRICE,PRECSELLPRICE,CREATETIME) select SEQ_QUOTATIONDATAID_nextval(), (select TRADEDATE from sd_market_info),MEMBERID,COMMODITYID,OPENPRICEBUY,OPENPRICESELL,OPENTIME,CLOSEPRICEBUY,CLOSEPRICESELL,CLOSETIME,HIGHBUYPRICE,LOWBUYPRICE,HIGHSELLPRICE,LOWSELLPRICE,QUOTETIME,PRECBUYPRICE,PRECSELLPRICE,CREATETIME from cd_quotation_data where TRADEDATE=%s;""" %lastday)sql6=("""insert into st_commodity_settleprice(SEQ, COMMODITYID, USERID, TRADEDATE, ISLASTRECKON, SETTLEMENTTIMESLICEBEGIN, SETTLEMENTTIMESLICEEND, TRADEMODE, PRICEDATE, SETTLETYPE, SETTLEMENTBUYPRICE, SETTLEMENTSELLPRICE, MSETTLEMENTBUYPRICE, MSETTLEMENTSELLPRICE, HIGHESTSELLPRICE, HIGHESTBUYPRICE, LOWESTSELLPRICE, LOWESTBUYPRICE, BUYPRICE, SELLPRICE, PRECBUYPRICE, PRECSELLPRICE) select SEQ_COMMODITY_SETTLEPRICE_nextval(), COMMODITYID, USERID, (select TRADEDATE from sd_market_info), ISLASTRECKON, SETTLEMENTTIMESLICEBEGIN, SETTLEMENTTIMESLICEEND, TRADEMODE, PRICEDATE, SETTLETYPE, SETTLEMENTBUYPRICE, SETTLEMENTSELLPRICE, MSETTLEMENTBUYPRICE, MSETTLEMENTSELLPRICE, HIGHESTSELLPRICE, HIGHESTBUYPRICE, LOWESTSELLPRICE, LOWESTBUYPRICE, BUYPRICE, SELLPRICE, PRECBUYPRICE, PRECSELLPRICE from st_commodity_settleprice where TRADEDATE=%s;""" %lastday)list=[sql1,sql2,sql3,sql4,sql5,sql6]for sql in list: try: print("begin to execute this sql:%s" %sql) cursor.execute(sql) db.commit() except Exception as e: db.rollback() db.close() print("execute sql fail: " + str(e)) sys.exit()db.close() 展开
 我来答
扬帆自在图7
2017-06-07 · TA获得超过236个赞
知道小有建树答主
回答量:228
采纳率:0%
帮助的人:45.2万
展开全部
1234>>> li = [1,2,4,5]>>> li.insert(2,3)>>> li[1, 2, 3, 4, 5]list.insert(index,var),第一个参数是列表索引,指向要插入的位置;第二个参数是要插入的元素
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式