Special Characters (Unicode, Ascii) in Python and MySQL

Discussion in 'Python' started by ronrsr, Jan 2, 2007.

  1. ronrsr

    ronrsr Guest

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

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

    I am having trouble storing text, as typed in latter 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

    perhaps the encoding of the database itself should be different? it is
    currenlty latin_swedish_ci

    Input and output is through a browser.

    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?



    here's the error message:

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



    the characters I am trying to add are startquote and endquote copied
    and pasted from Microsoft Word.



    Can anyone help me on this?

    bests,

    -rsr-
     
    ronrsr, Jan 2, 2007
    #1
    1. Advertisements

  2. On Mon, 2007-01-01 at 21:57 -0800, ronrsr wrote:
    > I have an MySQL database called zingers. The structure is:
    >
    > zid - integer, key, autoincrement
    > keyword - varchar
    > citation - text
    > quotation - text
    >
    > I am having trouble storing text, as typed in latter 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
    >
    > perhaps the encoding of the database itself should be different? it is
    > currenlty latin_swedish_ci
    >
    > Input and output is through a browser.
    >
    > 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?
    >
    >
    >
    > here's the error message:
    >
    > UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position
    > 95: ordinal not in range(128)
    > args = ('ascii', "update zingers set keywords =
    > 'a;Action;b;Religi... \n \n \n ' where zid = 422", 95, 96, 'ordinal not
    > in range(128)')
    > encoding = 'ascii'
    > end = 96
    > object = "update zingers set keywords = 'a;Action;b;Religi... \n
    > \n \n ' where zid = 422"
    > reason = 'ordinal not in range(128)'
    > start = 95
    >
    >
    >
    > the characters I am trying to add are startquote and endquote copied
    > and pasted from Microsoft Word.
    >
    >
    >
    > Can anyone help me on this?


    Apparently not, since you've already posted this problem on December
    18th and got various responses. Did you read
    http://effbot.org/pyfaq/how-do-i-escape-sql-values-when-using-the-db-api.htm as Fredrik suggested in the earlier thread?

    -Carsten
     
    Carsten Haese, Jan 2, 2007
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ronrsr
    Replies:
    13
    Views:
    931
    Leo Kislov
    Dec 18, 2006
  2. ronrsr
    Replies:
    1
    Views:
    675
    Justin Ezequiel
    Feb 15, 2007
  3. rvino
    Replies:
    0
    Views:
    5,016
    rvino
    Aug 14, 2007
  4. Laszlo Nagy
    Replies:
    6
    Views:
    965
  5. Grzegorz ¦liwiñski
    Replies:
    2
    Views:
    1,352
    Grzegorz ¦liwiñski
    Jan 19, 2011
  6. Ruby Tuesday
    Replies:
    4
    Views:
    290
  7. kike
    Replies:
    0
    Views:
    275
  8. Alextophi
    Replies:
    8
    Views:
    872
    Alan J. Flavell
    Dec 30, 2005
Loading...