J.D. <jd.cor...@pearson.com> wrote: > My solution didn't work. I was able to get my Portuguese data to load by > decoding it in ISO-8859-1, but by decoding I lose all the special characters > like tildes. > > So I still don't understand how to get the engine to accept my data properly. > > J.D. > > On Tuesday, March 3, 2015 at 3:00:24 PM UTC-7, J.D. wrote: > I actually figured this out..... > > It had nothing to do with my SQLAlchemy create_engine configuration. > > The data I was trying to create an object with was in ISO-8859-1 format, so I > just had to construct my Object the text decoded properly. > > Once I did this, the data was inserted into my sqlite3 table just fine. > > > On Tuesday, March 3, 2015 at 1:58:32 PM UTC-7, J.D. wrote: > Hi, > > I am getting the following error, when I try to execute code to insert a new > row into one of my tables, and I've googled for answers and tried everything > I could find online and nothing seems to resolve the issue. > > 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)
the error means that your unicode string has to be passed to pysqlite as a Python unicode object, that is, in Python 2 it has to be with a “u”, u’my string’. if you’re losing encoding information, that means that the encoding you’re using to decode into unicode is probably not correct. Feel free to share the string literal and I can round trip it into SQLite for you. > I am using the following software: > > SQLAlchemy v0.9.8 > > SQLite 3.8.8.2. > > I am creating my engine as follows, > > engine = create_engine('sqlite+pysqlite:///prototype.db', module=sqlite) > > #engine.raw_connection().connection.text_factory = str > > #engine.connect().connection.connection.text_factory = str > > session = sessionmaker(bind=engine)() > > meta.Base.metadata.bind = engine > > > meta.Base.metadata.create_all(engine) > > The object I am trying to insert via session.add(..) has a structure similar > to the following: (shortened for brevity) > > .. > > id = Column(Integer, primary_key=True, unique=True, nullable=False) > > title = Column(String, nullable=False) // This is the column that > gets the Portuguese data with unicode characters -- I've tried using the > column type Unicode > > # title = Column(Unicode, nullable=False) > > book_id = Column(Integer, nullable=False) > > > code = Column(Integer, nullable=False) > > ... > > I've tried setting the text_factory on the connection to no avail. I'm at a > loss how to fix this so I can insert my data with unicode chars. > > Here is the SQL that is generated for the insert > > > It is highly recommended that you instead just switch your application to > Unicode strings. u'INSERT INTO books (title, book_id, code) VALUES (?, ?, ?)' > ('Demana/Blitzer: Pr\x8e-c\x87lculo, 2e', '93810', 'removed') > > I would appreciate some insight to how to fix this issue so I can insert my > data. > > Thanks, > > J.D. > > > > > > > > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy+unsubscr...@googlegroups.com. > To post to this group, send email to sqlalchemy@googlegroups.com. > Visit this group at http://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.