Get SQLAlchemy to encode correctly strings with cx_Oracle
<p>My problem is that SQLAlchemy seems to be writing the text not properly encoded in my Oracle database.</p>

<p>I include fragments of the code below:</p>

<pre><code>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()
</code></pre>

<p>If now I read the contents of the database, I get printed something like:</p>

<blockquote>
  <p>????????qwerty</p>
</blockquote>

<p>instead of the original:</p>

<blockquote>
  <p>Ã¤Ã¼Ã¶Ãqwerty</p>
</blockquote>

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

<p>Thanks in advance!</p>

<p>I found a related topic, that actually answers my question:</p>

<p><a href="http://stackoverflow.com/questions/39780090/python-2-7-connection-to-oracle-loosing-polish-characters">Python 2.7 connection to oracle loosing polish characters</a></p>

<p>You simply add the following line, before creating the database connection:</p>

<pre><code>os.environ["NLS_LANG"] = "GERMAN_GERMANY.UTF8"
</code></pre>

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

<p><a href="https://docs.oracle.com/cd/E23943_01/bi.1111/b32121/pbr_nls005.htm#RSPUB23733" rel="nofollow">Oracle documentation on Unicode Support</a></p>

python