dealing with special characters in Python and MySQL

ronrsr ronrsr at gmail.com
Mon Dec 18 01:02:11 EST 2006


I have an MySQL database called zingers. The structure is:

     zid - integer, key, autoincrement
    keyword - varchar
    citation - text
    quotation - text

the encoding and collation is utf-8


I am having trouble storing text, as typed in last two fields. Special
characters and punctuation all seem not to be stored and retrieved
correctly.

Special apostrophes and single quotes from Microsoft Word are causing a
special problem, even though I have ''ed all 's

error messages, when trying to save to database:

 UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position
71: ordinal not in range(128)
      args = ('ascii', "update zingers set keywords = ' aaaaaa;Action',
...ation = '''''''''''''\n\n ' where zid = 422", 71, 72, 'ordinal not
in range(128)')
      encoding = 'ascii'
      end = 72
      object = "update zingers set keywords = ' aaaaaa;Action',
...ation = '''''''''''''\n\n ' where zid = 422"
      reason = 'ordinal not in range(128)'
      start = 71


I think my problem may be that I need to encode the string before
saving it in the databse. Can anyone point me in the right direction
here? 




Thanks so much,




More information about the Python-list mailing list