MySql Connector (python) and SQLAlchemy Unicode problem
I am using the mysql connector (https://launchpad.net/myconnpy) with SQLAlchemy and, though the table is definitely UTF8开发者_如何学JAVA, any string columns returned are just normal strings not unicode. The documentation doesn't list any specific parameters for UTF8/unicode support for the mysql connector driver so I borrowed from the mysqldb driver. Here is my connect string:
mysql+mysqlconnector://user:pass@myserver.com/mydbname?charset=utf8&use_unicode=0
I'd really prefer to keep using this all-python mysql driver. Any suggestions?
To work with Unicode python objects you should set the optional parameter convert_unicode to True when specifying a character column type:
users = Table('users', metadata,
Column('id', Integer, primary_key=True)
Column('name', String(100, convert_unicode=True))
You could also use the Unicode type. Check the documentation for details: String and Unicode.
Sorry, i don't know about the connector, i use MySQLDB and it is working quite nicely. I work in UTF8 as well and i didn't have any problem.
精彩评论