471,354 Members | 1,470 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

cx_Oracle: Non-ASCII characters handling with different versions

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)
Nov 13 '07 #1
3 4627
En Tue, 13 Nov 2007 13:37:16 -0300, Benjamin Hell <bh***@spamfence.net>
escribió:
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.

--
Gabriel Genellina

Nov 14 '07 #2
Benjamin Hell wrote:
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_hom e1\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.
Nov 14 '07 #3
On Nov 14, 2:03 pm, Benjamin Hell <bh...@spamfence.netwrote:
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_hom e1\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
Nov 16 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by GrayGeek | last post: by
8 posts views Thread by Rodrigo Daunaravicius | last post: by
1 post views Thread by Greg Lindstrom | last post: by
1 post views Thread by Maxim Kuleshov | last post: by
5 posts views Thread by Daniel | last post: by
4 posts views Thread by infidel | last post: by
1 post views Thread by lblr33 | last post: by
7 posts views Thread by Carl K | last post: by
1 post views Thread by Lukas Ziegler | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.