error
sqlalchemy.exc.ProgrammingError: (ProgrammingError) You must not use 8-bit bytestrings 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 category (parent_id, category_name) VALUES (?, ?)' (999, '\xa4\xa2')
対策
from sqlalchemy.interfaces import PoolListener
class SetTextFactory(PoolListener):
def connect(self, dbapi_con, con_record):
dbapi_con.text_factory = lambda x: unicode(unescape(x), "euc-jp", "ignore")
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
def create_session():
engine = create_engine('sqlite:///./test.db', echo=False, listeners=[SetTextFactory()])
Session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=engine))