473,388 Members | 1,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 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 4817
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: GrayGeek | last post by:
After cx_Oracle and the related Oracle tools for Python 2.2.3 + Boa-constructor on Win2000, I added "import cx_Oracle" to the top of a test script. It gives me an error about being unable to find...
1
by: Benson, John | last post by:
Hi, I'm a non-Oracle guy just starting to use Python to explore Oracle. I enclose the Python command prompt log for the usage example further down with only the user, password and host names...
8
by: Rodrigo Daunaravicius | last post by:
I can't get this configuration working: cx_Oracle 4.0.1 Oracle 8.0.6 Python 2.3.3 Win NT4.0 SP6fc My first shot at the problem was just running the installation thingie pre-built for...
1
by: Greg Lindstrom | last post by:
>Shouldn't this be '/u01/app/oracle/product/9.2.0' ? Based on the following values, that's what I'd expect. I changed the ORCALE_HOME environment variable to the above suggested value and got a...
1
by: Maxim Kuleshov | last post by:
Hello! Trying to fetch long varchar2 column and get the following error: cx_Oracle.DatabaseError: column at array pos 0 fetched with error: 1406 i.e. string buffer is not much enough to...
5
by: Daniel | last post by:
Hello from Brazil :-) I'm trying to bring cx_Oracle alive on my Python 2.4.1 @ HP-UX 11 (suckz) and Oracle 10.1.0 64bits without success I've already tryied the suggestions from Bernard Delmée...
4
by: infidel | last post by:
I have a stored procedure that has a single output parameter. Why do I have to pass it a string big enough to hold the value it is to receive? Why can't I pass an empty string or None? >>>...
1
by: lblr33 | last post by:
I downloaded cx_Oracle from http://www.cxtools.net/default.aspx?nav=cxorlb and selected the windows installer for Oracle 8i, Python 2.4 >From the readme.txt file: BINARY INSTALL: Place the...
7
by: Carl K | last post by:
I am trying to use this: http://python.net/crew/atuining/cx_Oracle/html/cx_Oracle.html it is a real module, right? sudo easy_install cx_Oracle did not easy_install cx_Oracle. ...
1
by: Lukas Ziegler | last post by:
Hi, I want to get an access to an oracle database. For that I found the module cx_oracle (http://www.python.net/crew/atuining/cx_Oracle/) and I have installed the version 'Windows Installer...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.