I have a MySQL database defined with collation UTF8. A table 'clientes' and all its columns are specified as UTF8.
DROP TABLE IF EXISTS `clientes`;
CREATE TABLE IF NOT EXISTS `clientes` (
`ID` varchar(35) NOT NULL DEFAULT '',
`nombre` varchar(255) NOT NULL DEFAULT '',
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `clientes` (`ID`, `nombre`) VALUES
('111', 'María Español Marqués'),
('222', 'Paulo Conceiçao'));
Queries with MySQL clients (in terminal, phpmyadmin...) displays characters fine:
mysql> select * from clientes;
+-----+--------------------------+
| ID | nombre |
+-----+--------------------------+
| 111 | María Español Marqués |
| 222 | Paulo Conceiçao |
+-----+--------------------------+
2 rows in set (0.00 sec)
Now, I create the class with SQLAlchemy:
#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
from sqlalchemy import create_engine, ForeignKey
from sqlalchemy import Column, Date, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, backref
engine = create_engine('mysql://root:toor@localhost')
engine.execute("USE nTal")
Base = declarative_base()
class Cliente(Base):
__tablename__ = "clientes"
ID = Column(String(35), primary_key=True)
nombre = Column(String(255))
def __init__(self, nombre):
""""""
self.nombre = nombre
engine.dispose()
When I run a query with SQLAlchemy, I get odd characters with accents, spanish and portuguese simbols are not visible.
res = session.query(Cliente).all()
for cliente in res:
print cliente.ID + ", " + cliente.nombre
111, Mar�a Espa�ol Marqu�s
222, Paulo Concei�ao
Of course, I have search a lot about enconding and decoding, but the most I find is about errors, not about incorrect displaying.
Thanks in advance.