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']))

 

标签: mysql, pymysql

相关文章

添加新评论