#215 UnicodeEncodeError: 'latin-1' codec can't encode characters

closed-fixed
MySQL (29)
5
2007-12-26
2007-03-28
No

I have this
http://pylonshq.com/pasties/198
after upgrading mysqldb to 1.2.2 from 1.2.1 when selecting by value that contains non-latin characters:

res = list(model.Tag.selectBy(tag = tag))

the connection string is
sqlobject.dburi = mysql://****:****@localhost/pyneohuman?sqlobject_encoding=utf-8&charset=utf8 in development.ini

so it's not latin-1...

any ideas?

Discussion

  • Oleg Broytman

    Oleg Broytman - 2007-03-28

    Logged In: YES
    user_id=4799
    Originator: NO

    What is the version of SQLObject?

     
  • Mirinde Fekus

    Mirinde Fekus - 2007-03-29

    Logged In: YES
    user_id=1304728
    Originator: YES

    SQLObject-0.8.1-py2.4

     
  • Viktor Ferenczi

    Viktor Ferenczi - 2007-08-26

    Logged In: YES
    user_id=142612
    Originator: NO

    My config: Python 2.5.1, SQLObject 0.9.1, MySQL 4.1.11, MySQL-python-1.2.2
    DB with InnoDB tables, utf8_general_ci everywhere.
    SET NAMES utf8 issued as first SQL statement.

    This bug also appears in 0.9.1. Now works fine with modified mysql/mysqlconnection.py:

    @@ -28,10 +28,6 @@
    self.user = user
    self.password = password
    self.kw = {}
    - if MySQLdb.version_info[:3] >= (1, 2, 1):
    - self.need_unicode = True
    - else:
    - self.need_unicode = False
    for key in ("unix_socket", "init_command",
    "read_default_file", "read_default_group", "conv"):
    if key in kw:
    @@ -107,10 +103,6 @@
    # done by calling ping(True) on the connection.
    for count in range(3):
    try:
    - # For MySQLdb 1.2.1 and later, we go
    - # encoding->unicode->charset (in the mysql db)
    - if self.need_unicode and not isinstance(query, unicode):
    - query = unicode(query, self.encoding)
    return cursor.execute(query)
    except MySQLdb.OperationalError, e:
    if e.args[0] in (MySQLdb.constants.CR.SERVER_GONE_ERROR, MySQLdb.constants.CR.SERVER_LOST):

    and DB URI options: ?use_unicode=1&charset=utf8

    It seems to me that the need_unicode stuff is somehow buggy and not required, at least in my case.

     
  • Oleg Broytman

    Oleg Broytman - 2007-12-26

    Logged In: YES
    user_id=4799
    Originator: NO

    The patch you are proposing here has been applied in the repository. Will be in 0.7.10, 0.8.7 and 0.9.3 when they will be released.

     
  • Oleg Broytman

    Oleg Broytman - 2007-12-26
    • assigned_to: nobody --> phd
    • status: open --> closed-fixed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks