1 回答
I assume you're using the unicode version of wxPython under Python 2 (not Python 3).
The problem arises when you're calling the str
constructor on the result of self.Text.GetValue()
.
wxPython accept all kind of characters and return unicode strings. In your example, Textctrl.GetValue()
return the unicode string u"2′BR"
str()
try to convert it into a string, using the default encoding, which is ascii. Ascii can only represents 128 characters. The prime character "′", is not represented in ascii. That's why you have this error.
What is the encoding of your MySQL database? If you want to use strange characters like the "′" prime, you should set your database encoding to utf-8.
Then you should be able to do:
cur.execute("INSERT INTO TKtable (title) VALUES (%s)", (self.Text.GetValue(),))
You won't be able to successfully insert a character that doesn't exist in your database encoding. I think the prime "′" (code 2032 in utf-8) prime doesn't even exist in latin-1.