#140 unicode parameter not accepted

MySQLdb-1.2
closed
Andy Dustman
MySQLdb (285)
5
2014-08-14
2005-05-16
Martin Mokrejs
No

Hi Andy,
I'm trying to use unicode in my software, and either
I misunderstand "MySQLdb User's Guide" or something is
not supported in 1.2.1c3:

It says in the section related to connect parameters:
"unicode If set, CHAR and VARCHAR columns are returned
as Unicode strings, using the specified character set."

Traceback (most recent call last):
File "test30.py", line 24, in ?
c = sql_io.DBHandler()
File "../sql_io.py", line 73, in init
self._connection = connect(conv=_type_conv,
read_default_file=_file, read_default_group='xxx',
init_command='SET AUTOCOMMIT=0', unicode='utf-8')
File
"/usr/lib/python2.3/site-packages/MySQLdb/init.py",
line 66, in Connect
return Connection(*args, kwargs)
File
"/usr/lib/python2.3/site-packages/MySQLdb/connections.py",
line 134, in
init
super(Connection, self).init(*args, kwargs2)
TypeError: 'unicode' is an invalid keyword argument for
this function

What's wrong? I'd appreciate a bit more information on
the behavior I get:

1) Will all CHAR, VARCHAR column data be returned as
unicode?

2) Can I get some as simple strings as I was used to?

3) Some example how you create the mysql column
definitions and what output you get in mysql(1)
commadline client and what through mysql-python?

Discussion

  • Logged In: YES
    user_id=84682

    The parameters for connect() has been changed.

    Use : connect(...... , use_unicode=True)
    Instead of: connect( ..... , unicode='utf8')

    Character encoding is fetched from the curren database
    connection. Result sets are unicode (on database string types).

    /Marcus

     
  • Andy Dustman
    Andy Dustman
    2005-05-17

    Logged In: YES
    user_id=71372

    Yes, I need to update the User's Guide for 1.2.
    unicode=<charset> was correct for 1.0.

     
  • Deron Meranda
    Deron Meranda
    2005-08-17

    Logged In: YES
    user_id=847188

    Here's some additional clarification that may also help...
    It seems you still need to insure that your "my.cnf" file has a
    unicode-capable character set, or else you'll also get an
    invalid-keyword error. Something like,

    [MySQLdb]
    default_character_set=utf8

    Then should check first that your connection is indeed utf8,

    db = MySQLdb.connect( ...., use_unicode=True )
    db.character_set_name()
    --> 'utf8'

     
  • Andy Dustman
    Andy Dustman
    2006-02-27

    Logged In: YES
    user_id=71372

    Docs are fixed.