pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'empire on which the sun never sets.'', ' ', 'T' )' at line 1")
报错如上,
解决方案:
使用
pymysql.escape_string()
例如:
def insert_data(in_title, in_url, in_time,tname="ques"): sql2 = "INSERT INTO %s (question, \ choice, answer) \ VALUES ('%s', '%s', '%s' )" % \ (tname,in_title, in_url, in_time) #执行数据库更新命令 cur.execute(sql2) con.commit() insert_data(pymysql.escape_string(x['question']),pymysql.escape_string(x['choice']), (x['answer']))
版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)
作者: Austin 发表日期:2020-06-25 10:18
分类: 所有文章