"Interpret 8-bit bytestrings" error in Sqlalchemy

Asked

Viewed 123 times

0

I’m starting with Sqlalchemy and came across this mistake:

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 the charset ('utf-8')?
Version of Python 2.7.6

1 answer

1


To work with Unicode use:

#-*- coding: utf-8 -*-
from __ future__ import absolute_import, unicode_literals

Browser other questions tagged

You are not signed in. Login or sign up in order to post.