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. Advertisements

  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. Advertisements

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. Robert Mark Bram
    Replies:
    0
    Views:
    4,365
    Robert Mark Bram
    Sep 28, 2003
  2. ygao

    unicode wrap unicode object?

    ygao, Apr 8, 2006, in forum: Python
    Replies:
    6
    Views:
    784
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
    Apr 8, 2006
  3. Gabriele *darkbard* Farina

    Unicode digit to unicode string

    Gabriele *darkbard* Farina, May 16, 2006, in forum: Python
    Replies:
    2
    Views:
    713
    Gabriele *darkbard* Farina
    May 16, 2006
  4. gabor
    Replies:
    13
    Views:
    829
    Leo Kislov
    Nov 18, 2006
  5. Keith Hughitt
    Replies:
    5
    Views:
    4,630
    kiranpvsr
    Dec 7, 2012
  6. Grzegorz ¦liwiñski
    Replies:
    2
    Views:
    1,332
    Grzegorz ¦liwiñski
    Jan 19, 2011
  7. Chirag Mistry
    Replies:
    6
    Views:
    376
    Ollivier Robert
    Feb 8, 2008
  8. Roy Smith
    Replies:
    1
    Views:
    213
    Roy Smith
    Mar 30, 2013
Loading...