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

分类: 所有文章,数据库

相关文章

2021.06.22   Python小技巧:pymysql像pymongo一样插入字典数据

2020.07.27   MySQL——导入导出.sql文件

2020.02.23   mysql 使用auto_increment关键字使ID字段自增 | pymysql

添加新评论