0

If I try to run a python file with this line in it:

cursor.execute("SELECT GameName FROM GamesTable WHERE GameName = 'Sid Meier's Civilization® IV'")

PuTTY gives me the error:

pymysql.err.ProgrammingError: (1064, u"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 's
Civilization\xae IV'' at line 1")

So it clearly can't read the ® symbol.

I've searched around and people said to be sure that the Remote Character Set is UTF-8, which it is.

Also, PuTTY seems to handle the symbol fine - if I just write print "®" then it correctly prints the symbol. It is only when trying to use pymysql to reach the sql server that it seems to have a problem.

1 Answers1

0

unicode error ? (assuming python 2)

gname = "Sid Meier's Civilization" + unichr(174) + "IV'"

then

gname.encode('utf-8')

which gives "Sid Meier's Civilization\xc2\xae IV"

https://docs.python.org/2/howto/unicode.html

lxx
  • 1,326
  • 20
  • 30
  • I don't understand what you mean, but to be clear python can read it just fine. Like if I make the whole python script just "print ®" then it does show ® in Putty. – fefewaf feaf Jan 17 '15 at 02:21
  • Sorry I didn't explain that properly its the terminal encoding cuasing that as you haven't set it. So mystring.encode('utf-8' )http://stackoverflow.com/questions/492483/setting-the-correct-encoding-when-piping-stdout-in-python http://stackoverflow.com/questions/6396659/how-do-you-get-the-encoding-of-the-terminal-from-within-a-python-script – lxx Jan 18 '15 at 04:22