"Interpret 8-bit bytestrings" error in SQLAlchemy

0

I'm starting with SQLAlchemy and I came across this error:

 
sqlalchemy.exc.ProgrammingError: (ProgrammingError) You must not use 8-bit bytes
trings unless you use a text_factory that can interpret 8-bit bytestrings (like
text_factory = str). 
It is highly recommended that you instead just switch your application to Unicode strings. 
u'INSERT INTO algoritimo ("nomeAlgoritimo", classe, "estruturaDados", "complexidadePiorCaso",
"complexidadeMedioCaso", "complexidadeMelhorCaso", "complexidadeEspacos", "pseudoAlgoritimo") VALUES (?, ?, ?, ?, ?, ?, ?, ?)' 
('Ordena\xe7\xe3o Sele\xe7\xe3o', 'Algoritmo de oderna\xe7\xe3o', '
Array, Listas ligadas', 'O(n^2)', 'O(n^2)', 'O(n^2)', 'O(n) total, O(1) auxiliar', '')

Code

 
Base = declarative_base()
engine = create_engine('sqlite:///classificacao_pesquisa.db')

class Algoritimo(Base):
    __tablename__ = 'algoritimo'

    id = Column(Integer, primary_key=True)
    nomeAlgoritimo = Column(String(50))
    classe = Column(String(250))
    estruturaDados = Column(String(50))
    complexidadePiorCaso = Column(String(50))
    complexidadeMedioCaso = Column(String(50))
    complexidadeMelhorCaso = Column(String(50))
    complexidadeEspacos = Column(String(50))
    pseudoAlgoritimo = Column(String(4000))

How can I set charset ('utf-8') ? Version of Python 2.7.6

    
asked by anonymous 26.05.2014 / 21:24

1 answer

1

To work with Unicode use:

#-*- coding: utf-8 -*-
from __ future__ import absolute_import, unicode_literals
    
27.05.2014 / 18:36