MySQLdb

Discussion in 'Python' started by slukas, Jan 15, 2004.

  1. slukas

    slukas Guest

    Hello
    Sorry for my English.
    I want add the new record to Mysql database. When I use my script I got
    an exception "UnicodeEncodeError: 'ascii' codec can't encode character
    u'\xe4' in position 12: ordinal not in range(128).
    When I add line
    sys.stdout = codecs.lookup('utf-8')[-1](sys.stdout)
    to my script i see the var on the screen but I can't add var to database.

    Any idea?
    Thanks!
    Lukas
    slukas, Jan 15, 2004
    #1
    1. Advertising

  2. Lukas> I want add the new record to Mysql database. When I use my script
    Lukas> I got an exception "UnicodeEncodeError: 'ascii' codec can't
    Lukas> encode character u'\xe4' in position 12: ordinal not in
    Lukas> range(128).

    Lukas,

    You will need to encode your Unicode objects before stuffing the resulting
    strings into MySQL. For example:

    utf8foo = foo.encode("utf-8")
    c.execute("insert into blah blah blah", (..., utf8foo, ...))

    instead of

    c.execute("insert into blah blah blah", (..., foo, ...))

    Skip
    Skip Montanaro, Jan 15, 2004
    #2
    1. Advertising

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. Alan Little

    can't import MySQldb on OS X

    Alan Little, Jun 25, 2003, in forum: Python
    Replies:
    0
    Views:
    819
    Alan Little
    Jun 25, 2003
  2. Skip Montanaro

    Re: Problem with MySQLdb on Mac OS X...

    Skip Montanaro, Jul 12, 2003, in forum: Python
    Replies:
    5
    Views:
    372
    Michael S. Jessop
    Jul 16, 2003
  3. Mike M
    Replies:
    1
    Views:
    318
  4. Dave Harrison

    MySQLdb and egenix mxDateTime dumps core

    Dave Harrison, Aug 5, 2003, in forum: Python
    Replies:
    0
    Views:
    322
    Dave Harrison
    Aug 5, 2003
  5. Dave Harrison

    using like and % in MySQLdb

    Dave Harrison, Aug 7, 2003, in forum: Python
    Replies:
    0
    Views:
    302
    Dave Harrison
    Aug 7, 2003
Loading...

Share This Page