Menu

problem charset error

Help
2006-08-11
2012-09-19
  • Hugues Bonvin

    Hugues Bonvin - 2006-08-11

    Hi,
    I have a problem with the connection on mysql 5.0 with the “charset” value.
    The programs run on windows with the “MySQL-python.exe1.2.1_p2-win32-py2.4.exe” and “mysql-essential-5.0.24-win32.msi” versions

    With the following code
    db =MySQLdb.Connect(host, user, password, db=Name, port=lport)

    print "db char set : ", db.charset

    I get this error :
    db char set : erreur <open file '<stderr>', mode 'w' at 0x0096E0B0>
    <open file '<stdout>', mode 'w' at 0x0096E068>

    The first problem with this version of Mysql and Python, is a problem with accent chars like éàäöü…If I don’t print the db.charset the application work without accent.
    With accent I get this error :
    cursor.execute(qry)
    File "C:\Python24\Lib\site-packages\MySQLdb\cursors.py", line 146, in execute
    query = query.encode(charset)
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 72: ordinal
    not in range(128)

    The database has the default character set to latin1.
    All query work on older version of Mysql and Python.

    Thank you in advance,
    Hugues

     
    • Hugues Bonvin

      Hugues Bonvin - 2006-08-13

      Hi,
      The following code works without error :
      print "db char set : ", db.character_set_name()

      I get : latin 1

      For my accent problem, I comment out the line 146 of cursors.py.
      The program works with accent.
      It’s not really elegant, but I can do what I need.

       
    • Jeremiah C. Foster

      I am getting the same problem but on a different operating system. Here is the error message I get from python:

      Traceback (most recent call last):
      File "/home/jeremiah/code/python/filterbatch_categories.py", line 72, in ?
      cursor.execute(searchSQLString)
      File "/usr/local/lib/python2.3/site-packages/MySQLdb/cursors.py", line 146, in execute
      query = query.encode(charset)
      UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 627: ordinal not in range(128)

       
    • Helger Bouterse

      Helger Bouterse - 2006-09-14

      Yep. Thanks Andy. Works perfectly!!

      Kind regards,
      Helger

       
    • Helger Bouterse

      Helger Bouterse - 2006-09-14

      I just migrated to a few new servers. Running MySQL-python-1.2.1_p2, Python 2.4.3, mysql 4.1.12 on both FreeBSD and RH linux and ALL my old applics are broken due to the same problem described in this thread.
      The 'db.character_set_name()' returnes 'latin1' as it should, so that is not the problem.

      Disabling all 'query.encode(charset)' lines in cursors.py (as suggested by Hugues) does indeed help, but I assume Andy put those lines there for a reason ;-).
      Is there any structural solution for this problem?
      Any help is appreciated.

      Thanks in advance,
      Helger

       
      • Andy Dustman

        Andy Dustman - 2006-09-14

        Try 1.2.2b1

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.