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()
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询