真实世界的Python仪器监控:数据采集与控制系统自动化 中文pdf扫描版[84MB]
tDate = time.strftime("%Y-%m-%d",time.localtime(time.time()))
sql = " insert into content(catid,typeid,title,adddate) values ('%d','%d','%s','%Y-%m-%d') " % (23,0,titleContents,tDate)
修改为
sql = " insert into content(catid,typeid,title,adddate) values ('%d','%d','%s','%%Y-%%m-%%d') " % (23,0,titleContents,tDate)
产生原因:因为python执行的sql中存在类似DATE_FORMAT(CREATE_TIME, ‘%Y-%m-%d’) 的写法,其中%Y与python的参数%s冲突
解决方法如下:
使用:str_to_date(%s,'%%Y-%%m-%%d')
sql = " insert into 3qphp_content(catid,typeid,title,adddate) values ('%d','%d','%s',str_to_date(%s,'%%Y-%%m-%%d')) " % (23,0,titleContents,tDate)
转载请注明:谷谷点程序 » python 插入mysql信息提示错误unsupported format character 'Y' (0x59) at index 356