Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Python insert into SQL unicode error

I have the following error :

 db = MySQLdb.connect(host="localhost", # host
 user="root", # username
 passwd="", # password
 db="test",charset='utf8') #
 cur = db.cursor() 
 x = "испытание" # random unicode characters
 sql = "INSERT INTO links(test) VALUES(N'%s');"
 lst = ( x ) #x is unicode data
 cur.execute(sql,lst)

The error I get is : MySQL Error [1064]: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax ...

Answer*

Draft saved
Draft discarded
Cancel
1
  • Note this code suffers from SQL-injection. Prefer to use parameterised queries. Also HTML-injection (XSS). Commented Jan 23, 2015 at 15:18

default

AltStyle によって変換されたページ (->オリジナル) /