MySQLdb and Unicode

  • Thread starter Achim Domma (Procoders)
  • Start date
A

Achim Domma (Procoders)

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
 
D

deelan

Achim said:
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.''
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top