0

My problem is that SQLAlchemy seems to be writing the text not properly encoded in my Oracle database.

I include fragments of the code below:

engine = create_engine("oracle://%s:%s@%s:%s/%s?charset=utf8"%(db_username, db_password, db_hostname,db_port, db_database), encoding='utf8')    
connection = engine.connect()
session    = Session(bind = connection)    

class MyClass(DeclarativeBase):
    """
    Model of the be persisted
    """        
    __tablename__ = "enconding_test"

    id              = Column(Integer, Sequence('encoding_test_id_seq'),primary_key = True)    

    blabla  = Column(String(255, collation='utf-8'), default = '')           
    autoload = True    

content = unicode("äüößqwerty","utf_8")
t = MyClass(blabla=content.encode("utf_8"))

session.add(t)
session.commit()

If now I read the contents of the database, I get printed something like:

????????qwerty

instead of the original:

äüößqwerty

So basically my question is what do I have to do, to properly store these German characters in the database?

Thanks in advance!

ArK
  • 20,698
  • 67
  • 109
  • 136
cecilin
  • 11
  • 4

1 Answers1

1

I found a related topic, that actually answers my question:

Python 2.7 connection to oracle loosing polish characters

You simply add the following line, before creating the database connection:

os.environ["NLS_LANG"] = "GERMAN_GERMANY.UTF8"

Additional documentation about which strings you need for different languages are found at the Oracle website:

Oracle documentation on Unicode Support

Community
  • 1
  • 1
cecilin
  • 11
  • 4