精通Python自然语言处理pdf免费下载
pymysql.err.ProgrammingError: 1064 (Python字符串转义问题)使用pymysql.escape_string()方法解决
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 \'pgc-img-caption"></p>\', \'<p><strong>男人到了哪个年龄段,精子质量\' at line 1')
源码:
self.cur.execute('INSERT into kandian (title,content)values("%s","%s")' % (item['title'],item['content']))
原因:
item['title']和item['content']里面含有引号等需要转义的字符,可能会发生如上错误。
解决方法:
使用pymysql.escape_string()方法
self.cur.execute('INSERT into kandian (title,content)values("%s","%s")' % (pymysql.escape_string(item['title']),pymysql.escape_string(item['content'])))
转载请注明:谷谷点程序 » pymysql.err.ProgrammingError (1064, You have an error in your SQL syntax; check