cx_Oracle: Non-ASCII characters handling with different versions

B

Benjamin Hell

Hi!

I have a problem with the cx_Oracle module (Oracle database access):

On a computer with cx_Oracle version 4.1 (Python 2.4.3, Oracle 10g)
I can get query results consisting of strings including non-ASCII
characters, e.g. the code example below outputs "é 0xe9" (which is
the correct ISO-8859-1 hex code for "é"). On a newer installation
with cx_Oracle 4.3.3 (Python 2.5.1, connecting to the same Oracle
10g server) these characters are interpreted as ASCII (output "e
0x65"). The database encoding is the default (and it's the same DB
in both cases anyways); I have no NLS environment environment
variables set on either system (I'm running cygwin). The HISTORY
file of my more recent cx_Oracle names a few changes related to
character sets, but noone strikes me to be relevant for this case.

There is non-ASCII data strings in a database, and I need to find a
way to get it out correctly.


Is anybody able to help me?

Thanks!

Ben



#!/usr/bin/env python
import cx_Oracle
database = cx_Oracle.connect('login/pass@server')
curs = database.cursor()
sql = """SELECT CHR(233) FROM DUAL"""
curs.execute(sql)
result = curs.fetchone()[0]
print result, "0x%x" % ord(result)
 
G

Gabriel Genellina

I have a problem with the cx_Oracle module (Oracle database access):

On a computer with cx_Oracle version 4.1 (Python 2.4.3, Oracle 10g)
I can get query results consisting of strings including non-ASCII
characters, e.g. the code example below outputs "é 0xe9" (which is
the correct ISO-8859-1 hex code for "é"). On a newer installation
with cx_Oracle 4.3.3 (Python 2.5.1, connecting to the same Oracle
10g server) these characters are interpreted as ASCII (output "e
0x65"). The database encoding is the default (and it's the same DB
in both cases anyways); I have no NLS environment environment
variables set on either system (I'm running cygwin). The HISTORY
file of my more recent cx_Oracle names a few changes related to
character sets, but noone strikes me to be relevant for this case.

I've never used cx_Oracle, but Python (2.4.4 or 2.5.1) + pyodbc + the
Oracle ODBC driver works fine for me using non-ascii characters.
 
B

Benjamin Hell

Benjamin said:
On a computer with cx_Oracle version 4.1 (Python 2.4.3, Oracle 10g)
I can get query results consisting of strings including non-ASCII
characters, e.g. the code example below outputs "é 0xe9" (which is
the correct ISO-8859-1 hex code for "é"). On a newer installation
with cx_Oracle 4.3.3 (Python 2.5.1, connecting to the same Oracle
10g server) these characters are interpreted as ASCII (output "e
0x65").

It's solved: Because of a local full Oracle DB installation the
"working" box had the registry key
HKEY_LOCAL_SYSTEM\SOFTWARE\ORACLE\KEY_OraBD10g_home1\NLS_LANG set to
"AMERICAN_AMERICA.WE8MSWIN1252". A similar key was missing on the
other box. I added HKEY_LOCAL_SYSTEM\SOFTWARE\ORACLE\NLS_LANG with
the same value and now it works.
 
D

dwahli

It's solved: Because of a local full Oracle DB installation the
"working" box had the registry key
HKEY_LOCAL_SYSTEM\SOFTWARE\ORACLE\KEY_OraBD10g_home1\NLS_LANG set to
"AMERICAN_AMERICA.WE8MSWIN1252". A similar key was missing on the
other box. I added HKEY_LOCAL_SYSTEM\SOFTWARE\ORACLE\NLS_LANG with
the same value and now it works.

You could use environment variable NLS_LANG to set it at run time
with:

os.environ["NLS_LANG"] = "AMERICAN_AMERICA.WE8MSWIN1252"
import cx_Oracle
....

This way you don't have to deal with registry on each box.
Note that os.environ["NLS_LANG"] must be BEFORE import cx_Oracle.

Domino
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top