错误代码:ValueError: unsupported format character 'Y' (0x59) at index 89
错误语句:sql = "select id, role_id, username, nickname, sex, email, tel, intro, date_format(createtime,'%Y-%m-%d %H:%I:%s') as createtime from user limit %s, %s" % (pagenum, pagesize)
原因:sql语句中的date_format(createtime,'%Y-%m-%d %H:%I:%s')中的“%”与python的变量参数写法冲突。
解决办法之一:将sql语句中的变量参数“%s”从句中分离出来,用拼接的方式写,
如"select * from user where username = " + "'%s'" % username
改正语句:sql = "select id, role_id, username, nickname, sex, email, tel, intro, date_format(createtime,'%Y-%m-%d %H:%I:%s') as createtime from user limit " + "%s," % pagenum + "%s" % pagesize