MySQLdb and Unicode

Discussion in 'Python' started by Achim Domma (Procoders), May 20, 2005.

  1. Hi,

    I try to write unicode strings to a MySQL database via MySQLdb.
    According to the documentation I should pass 'utf-8' as keyword
    parameter to the connect method. But then I get the following error:


    Traceback (most recent call last):
    File "C:\develop\SyynX\unicode_test.py", line 7, in ?
    con=MySQLdb.connect(host='localhost',db='unicode_test',unicode='utf-8')
    File "C:\Python24\Lib\site-packages\MySQLdb\__init__.py", line 66, in
    Connect
    return Connection(*args, **kwargs)
    File "C:\Python24\Lib\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


    I'm using version 1.2 of MySQLdb. Any hint what I'm doing wrong?

    regards,
    Achim
     
    Achim Domma (Procoders), May 20, 2005
    #1
    1. Advertising

  2. Achim Domma (Procoders)

    deelan Guest

    Achim Domma (Procoders) wrote:
    > Hi,
    >
    > I try to write unicode strings to a MySQL database via MySQLdb.
    > According to the documentation I should pass 'utf-8' as keyword
    > parameter to the connect method. But then I get the following error:
    >

    (...)
    >
    >
    > I'm using version 1.2 of MySQLdb. Any hint what I'm doing wrong?


    this is changed in 1.2, from the Connection class docstring:

    "use_unicode"

    ''If True, text-like columns are returned as unicode objects
    using the connection's character set. Otherwise, text-like
    columns are returned as strings. columns are returned as
    normal strings. Unicode objects will always be encoded to
    the connection's character set regardless of this setting.''

    --
    @prefix foaf: <http://xmlns.com/foaf/0.1/> .
    <#me> a foaf:person ; foaf:nick "deelan" ;
    foaf:weblog <http://blog.deelan.com/> .
     
    deelan, May 20, 2005
    #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. Keith Hughitt
    Replies:
    5
    Views:
    4,183
    kiranpvsr
    Dec 7, 2012
  2. Grzegorz ¦liwiñski
    Replies:
    2
    Views:
    1,024
    Grzegorz ¦liwiñski
    Jan 19, 2011
  3. Chirag Mistry
    Replies:
    6
    Views:
    191
    Ollivier Robert
    Feb 8, 2008
  4. Roy Smith
    Replies:
    1
    Views:
    143
    Roy Smith
    Mar 30, 2013
  5. Terry Reedy
    Replies:
    0
    Views:
    93
    Terry Reedy
    Jan 7, 2014
Loading...

Share This Page