mysql - pymysql.err.ProgrammingError: can anyone help me -


import pymysql   f = open('c:\\users\allen\desktop\html style.txt', 'rb') array = [] in f.readlines():     array.append(i.decode('utf8')) str1 = ''.join(str(x) x in array)  conn = pymysql.connect(user='root', host='localhost', password='cwl19940125', database='news', charset='utf8') mycursor = conn.cursor() sql_insert = 'insert test(content) values ("%s");' % str1 mycursor.execute(sql_insert) conn.commit() mycursor.close() conn.close() 

error

pymysql.err.programmingerror: (1064, 'you have error in sql syntax; check manual corresponds mysql server version right syntax use near \'"\ufeff\t<section class="_135editor" data-tools="135编辑器" data-id="85433" style\' @ line 1') 

i print(sql_insert) let see clear

    insert test(content) values "<section class="_135editor" data-tools="135编辑器" data-id="85433" style="position: relative;">      <section class="135brush" data-style="color: inherit; box-sizing: border-box;line-height: 2em; text-align: center;" style="color: inherit; border-color: rgb(216, 40, 33); box-sizing: border-box; padding: 0px; margin: 0px;">             </section> </section>"; 

i add str , can't find syntax . need ,can me?

change

sql_insert = 'insert test(content) values ("%s");' % str1 

to

sql_insert = 'insert test(content) values ('%s');' % str1                                                ^^  ^^ 

be aware of single quotes here.

>>> qry = """insert posts(title, body) values('lorem ipsum', '%s')""" %sql >>> print(qry) insert posts(title, body) values('lorem ipsum', '<section class="_135editor" data-tools="135" data-id="85433" style="position: relative;">     <section class="135brush" data-style="color: inherit; box-sizing: border-box;line-height: 2em; text-align: center;" style="color: inherit; border-color: rgb(216, 40, 33); box-sizing: border-box; padding: 0px; margin: 0px;"> 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -