[cx-oracle-users] right way to use Unicode under Python 2.7?
Brought to you by:
atuining
From: Chris R. <chr...@hu...> - 2012-12-07 21:56:49
|
So, Unicode mode / WITH_UNICODE seems to have been removed a while ago (https://bitbucket.org/anthony_tuininga/cx_oracle/commits/33157874357bc4209 48b90c7db28865d0138a3e2 ), although it's still referenced in the docs in a couple places (http://cx-oracle.sourceforge.net/html/connection.html#Connection.encoding <http://cx-oracle.sourceforge.net/html/connection.html?highlight=encoding#C onnection.encoding> ). What, then, is currently The Right Way™ to setup cx_Oracle to completely use Unicode under Python 2.7? Doesn't seem to be working quite right out-of-the-box (nor are the error message or traceback particularly helpful): >>> query = u"SELECT COL_A, COL_B FROM some_db.some_table WHERE COL_A LIKE >>>:0 ESCAPE '@' ORDER BY COL_A ASC" >>> param_vals = [u"%☂%"] # U+2602 UMBRELLA >>> param_vals [u'%\u2602%'] >>> cur = connection.cursor() >>> cur.execute(query, param_vals) Traceback (most recent call last): File "<console>", line 1, in <module> UnicodeEncodeError: 'ascii' codec can't encode character u'\u2602' in position 1: ordinal not in range(128) Relevant versions: Python 2.7.3 cx_Oracle 5.1.2 Oracle Instant Client for Linux x86-64 11.2.0.3.0 Thanks, Chris Rebert |