Thread: [cx-oracle-users] RuntimeError: Unable to acquire Oracle environment handle
Brought to you by:
atuining
From: M. A. W. <maw...@gm...> - 2006-10-16 07:41:33
|
Hi All, i am executing python script as cgi, path of this script is in html page but got error RuntimeError: Unable to acquire Oracle environment handle (i solve this error , but not sure is this proper way) funny thing is i used sqlplus "user/password@connection" it worked fine got sql> prompt then i wrote a script file test.py import cx_Oracle db = cx_Oracle.connect("user/password@connection") cur = db.cursor() cur.execute("select * from emp") r = cur.fetchall() for i in r: print i it also worked fine, i thought my environment is proper. then i wrote cgi-script #!/usr/bin/python print 'content-type: text/html','\n'; import cgi import sys import cx_Oracle import os sys.stderr = sys.stdout db = cx_Oracle.connect('mukhtar/mukhtar@navi') but got error on browser (RuntimeError: Unable to acquire Oracle environment handle ) then explicitly I set ORACLE_HOME in script itself, it worked #!/usr/bin/python print 'content-type: text/html','\n'; import cgi import sys import cx_Oracle import os sys.stderr = sys.stdout os.putenv('ORACLE_HOME','/u01/app/oracle/product/9.2.0') # i just add this line, db = cx_Oracle.connect('mukhtar/mukhtar@navi') but got confused it ORACLE_HOME is set and working with normal script, why i need to put this line in cgi-script Thanks in Advance, Mukhtar |
From: Bartosz S. <get...@gm...> - 2008-11-27 16:42:19
|
Hi, I know that this problem is quite often and I found 1000 answers but in fact all of them are the same. And my issue is still here. Because my admin is not as good as he should, and nothing work as it should, i try to fix it on my own hand, so..... Admin installed Oracle Instant Client basic 10.2.0.4 (our remote Oracle database has the same version), and he installed it here: [bartek@batman ~]$ rpm -ql oracle-instantclient-basic-10.2.0.4-1 /usr/lib/oracle/10.2.0.4/client/bin/genezi /usr/lib/oracle/10.2.0.4/client/lib/libclntsh.so.10.1 /usr/lib/oracle/10.2.0.4/client/lib/libnnz10.so /usr/lib/oracle/10.2.0.4/client/lib/libocci.so.10.1 /usr/lib/oracle/10.2.0.4/client/lib/libociei.so /usr/lib/oracle/10.2.0.4/client/lib/libocijdbc10.so /usr/lib/oracle/10.2.0.4/client/lib/ojdbc14.jar [bartek@batman ~]$ Also, i found this: [bartek@batman ~]$ ls -R /usr/lib/oracle/10.2.0.3/ /usr/lib/oracle/10.2.0.3/: client /usr/lib/oracle/10.2.0.3/client: bin lib /usr/lib/oracle/10.2.0.3/client/bin: /usr/lib/oracle/10.2.0.3/client/lib: [bartek@batman ~]$ But it's empty. Ok, I downlaoded cx_Oracle 4.3.1 Fedora Core 5 RPM (Oracle 10g, Python 2.5) [1], unpacked it and made a quick hack: [bartek@batman ~]$ ls usr/local/lib/python2.5/st/ cx_Oracle-4.3.1-py2.5.egg-info cx_Oracle.so __init__.py __init__.pyc [bartek@batman ~]$ By default there are not any $ORACLE_* neither $TNS_ADMIN. [bartek@batman python2.5]$ python Python 2.5.1 (r251:54863, Nov 15 2007, 09:48:39) [GCC 3.4.6 20060404 (Red Hat 3.4.6-8)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import st.cx_Oracle as cx >>> cx.__file__ 'st/cx_Oracle.so' # as you see, we imported correct module >>> cx.version '4.3.1' >>> dsn = cx.makedsn(remote_ip, 1521, my_sid) >>> conn = cx.connect(l, p, dsn) Traceback (most recent call last): File "<stdin>", line 1, in <module> RuntimeError: Unable to acquire Oracle environment handle >>> I tried to add the following before importing cx_Oracle: os.environ['PATH'] = '/usr/lib/oracle:' + os.environ['PATH'] os.environ['ORACLE_HOME'] = '/usr/lib/oracle' os.environ['LD_LIBRARY_PATH'] = '/usr/lib/oracle' nothing has changed. Also tried to set those vars to /usr/lib/oracle/10.2.0.4/client/lib but no results anyone can help me? bart. [1] I tried the latest version but i get this: ImportError: libpython2.5.so.1.0: cannot open shared object file: No such file or directory |
From: Anthony T. <ant...@gm...> - 2008-11-27 17:55:35
|
First, confirm that you can use SQL*Plus to connect. The error "unable to acquire environment handle" implies some incompatibility between the version of Oracle used to compile cx_Oracle and the actual client you are using. Take a look at the environment variable ORACLE_HOME, PATH, LD_LIBRARY_PATH, etc. You can also run "ldd cx_Oracle.so" to see which libraries its trying to use. Hopefully that helps you move along. :-) Anthony On Thu, Nov 27, 2008 at 9:42 AM, Bartosz SKOWRON <get...@gm...> wrote: > Hi, > > I know that this problem is quite often and I found 1000 answers but > in fact all of them are the same. And my issue is still here. > > Because my admin is not as good as he should, and nothing work as it > should, i try to fix it on my own hand, so..... > > > Admin installed Oracle Instant Client basic 10.2.0.4 (our remote > Oracle database has the same version), and he installed it here: > [bartek@batman ~]$ rpm -ql oracle-instantclient-basic-10.2.0.4-1 > /usr/lib/oracle/10.2.0.4/client/bin/genezi > /usr/lib/oracle/10.2.0.4/client/lib/libclntsh.so.10.1 > /usr/lib/oracle/10.2.0.4/client/lib/libnnz10.so > /usr/lib/oracle/10.2.0.4/client/lib/libocci.so.10.1 > /usr/lib/oracle/10.2.0.4/client/lib/libociei.so > /usr/lib/oracle/10.2.0.4/client/lib/libocijdbc10.so > /usr/lib/oracle/10.2.0.4/client/lib/ojdbc14.jar > [bartek@batman ~]$ > > Also, i found this: > [bartek@batman ~]$ ls -R /usr/lib/oracle/10.2.0.3/ > /usr/lib/oracle/10.2.0.3/: > client > > /usr/lib/oracle/10.2.0.3/client: > bin lib > > /usr/lib/oracle/10.2.0.3/client/bin: > > /usr/lib/oracle/10.2.0.3/client/lib: > [bartek@batman ~]$ > > But it's empty. > > Ok, I downlaoded cx_Oracle 4.3.1 Fedora Core 5 RPM (Oracle 10g, Python > 2.5) [1], unpacked it and made a quick hack: > [bartek@batman ~]$ ls usr/local/lib/python2.5/st/ > cx_Oracle-4.3.1-py2.5.egg-info cx_Oracle.so __init__.py __init__.pyc > [bartek@batman ~]$ > > By default there are not any $ORACLE_* neither $TNS_ADMIN. > > [bartek@batman python2.5]$ python > Python 2.5.1 (r251:54863, Nov 15 2007, 09:48:39) > [GCC 3.4.6 20060404 (Red Hat 3.4.6-8)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import st.cx_Oracle as cx >>>> cx.__file__ > 'st/cx_Oracle.so' # as you see, we imported correct module >>>> cx.version > '4.3.1' >>>> dsn = cx.makedsn(remote_ip, 1521, my_sid) >>>> conn = cx.connect(l, p, dsn) > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > RuntimeError: Unable to acquire Oracle environment handle >>>> > > > I tried to add the following before importing cx_Oracle: > os.environ['PATH'] = '/usr/lib/oracle:' + os.environ['PATH'] > os.environ['ORACLE_HOME'] = '/usr/lib/oracle' > os.environ['LD_LIBRARY_PATH'] = '/usr/lib/oracle' > > nothing has changed. Also tried to set those vars to > /usr/lib/oracle/10.2.0.4/client/lib but no results > > anyone can help me? > bart. > > > [1] I tried the latest version but i get this: > ImportError: libpython2.5.so.1.0: cannot open shared object file: No > such file or directory > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > cx-oracle-users mailing list > cx-...@li... > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > |
From: Bartosz S. <get...@gm...> - 2008-11-27 18:14:38
|
On Thu, Nov 27, 2008 at 6:55 PM, Anthony Tuininga <ant...@gm...> wrote: > First, confirm that you can use SQL*Plus to connect. I don't have SQLPlus on the machine, and perhaps we couldn't install it > Take a look at the environment variable ORACLE_HOME, > PATH, LD_LIBRARY_PATH, etc. Take a look in what? I pasted you values of them, are they correct? > You can also run "ldd cx_Oracle.so" to see which libraries its trying to use. i will try it tommorow, cause i'm at home now. > Hopefully that helps you move along. :-) Thanks for your help :) |
From: Anthony T. <ant...@gm...> - 2008-11-27 18:28:59
|
On Thu, Nov 27, 2008 at 11:14 AM, Bartosz SKOWRON <get...@gm...> wrote: > On Thu, Nov 27, 2008 at 6:55 PM, Anthony Tuininga > <ant...@gm...> wrote: > >> First, confirm that you can use SQL*Plus to connect. > > I don't have SQLPlus on the machine, and perhaps we couldn't install it You can install it. The instant client has an optional package for that as well as an optional package for development purposes so that you can build yourself if necessary. >> Take a look at the environment variable ORACLE_HOME, >> PATH, LD_LIBRARY_PATH, etc. > > Take a look in what? I pasted you values of them, are they correct? Look at their values. They need to be consistent. I'm not using the instant client on my Linux machine so I'm not sure if ORACLE_HOME needs to be set or if it simply uses PATH and LD_LIBRARY_PATH. >> You can also run "ldd cx_Oracle.so" to see which libraries its trying to use. > > i will try it tommorow, cause i'm at home now. This might help you diagnose issues with your environment variables. >> Hopefully that helps you move along. :-) > > Thanks for your help :) You're welcome. :-) Anthony |
From: Bartosz S. <get...@gm...> - 2008-11-28 09:02:28
|
On Thu, Nov 27, 2008 at 7:28 PM, Anthony Tuininga <ant...@gm...> wrote: >>> You can also run "ldd cx_Oracle.so" to see which libraries its trying to use. > This might help you diagnose issues with your environment variables. libclntsh.so.10.1 => /usr/lib/libclntsh.so.10.1 (0xb7216000) libpthread.so.0 => /lib/tls/libpthread.so.0 (0xb7203000) libc.so.6 => /lib/tls/libc.so.6 (0xb70d7000) libnnz10.so => /usr/lib/libnnz10.so (0xb6ed2000) libdl.so.2 => /lib/libdl.so.2 (0xb6ece000) libm.so.6 => /lib/tls/libm.so.6 (0xb6eab000) libnsl.so.1 => /lib/libnsl.so.1 (0xb6e95000) /lib/ld-linux.so.2 (0x00bbc000) There is no reference to /usr/lib/oracle at all. Is it strange? |
From: Mark H. <mh...@pi...> - 2008-11-27 20:53:10
|
Anthony Tuininga wrote: > On Thu, Nov 27, 2008 at 11:14 AM, Bartosz SKOWRON <get...@gm...> wrote: >> On Thu, Nov 27, 2008 at 6:55 PM, Anthony Tuininga >> <ant...@gm...> wrote: >> >>> First, confirm that you can use SQL*Plus to connect. >> I don't have SQLPlus on the machine, and perhaps we couldn't install it > > You can install it. The instant client has an optional package for > that as well as an optional package for development purposes so that > you can build yourself if necessary. > >>> Take a look at the environment variable ORACLE_HOME, >>> PATH, LD_LIBRARY_PATH, etc. >> Take a look in what? I pasted you values of them, are they correct? > > Look at their values. They need to be consistent. I'm not using the > instant client on my Linux machine so I'm not sure if ORACLE_HOME > needs to be set or if it simply uses PATH and LD_LIBRARY_PATH. ORACLE_HOME doesn't need to be set. If you install into /usr/lib, you don't need to set LD_LIBRARY_PATH. I highly recommend this, as LD_LIBRARY_PATH discussions tend to be pretty uninteresting! PATH is only needed for locating sqlplus. The same applies for Mac OSX, with the note that LD_LIBRARY_PATH is changed to DYLD_LIBRARY_PATH. |
From: Bartosz S. <get...@gm...> - 2008-11-28 13:47:27
|
On Thu, Nov 27, 2008 at 9:53 PM, Mark Harrison <mh...@pi...> wrote: > If you install into /usr/lib, you don't need to set LD_LIBRARY_PATH. Ok, I've just resolved the issue by setting /usr/lib/oracle/10.2.0.4/client/lib into LD_LIBRARY_PATH thanks for support! |
From: Mark H. <mh...@pi...> - 2008-11-27 20:55:02
|
>> I tried to add the following before importing cx_Oracle: >> os.environ['PATH'] = '/usr/lib/oracle:' + os.environ['PATH'] >> os.environ['ORACLE_HOME'] = '/usr/lib/oracle' >> os.environ['LD_LIBRARY_PATH'] = '/usr/lib/oracle' IIRC, these need to be set outside the process, before it starts. |
From: Bartosz S. <get...@gm...> - 2008-11-28 09:00:53
|
On Thu, Nov 27, 2008 at 9:54 PM, Mark Harrison <mh...@pi...> wrote: >>> I tried to add the following before importing cx_Oracle: >>> os.environ['PATH'] = '/usr/lib/oracle:' + os.environ['PATH'] >>> os.environ['ORACLE_HOME'] = '/usr/lib/oracle' >>> os.environ['LD_LIBRARY_PATH'] = '/usr/lib/oracle' > IIRC, these need to be set outside the process, before > it starts. Nothing has changed. |
From: Bartosz S. <get...@gm...> - 2008-11-27 20:56:26
|
On Thu, Nov 27, 2008 at 9:53 PM, Mark Harrison <mh...@pi...> wrote: > PATH is only needed for locating sqlplus. sqlplus is required? why? |
From: Mark H. <mh...@pi...> - 2008-11-27 23:30:28
|
Bartosz SKOWRON wrote: > On Thu, Nov 27, 2008 at 9:53 PM, Mark Harrison <mh...@pi...> wrote: > >> PATH is only needed for locating sqlplus. > > sqlplus is required? why? I'm sorry, I was not clear. sqlplus is not necessary. The only reason PATH may be involved is for someone to run sqlplus without typing /my/path/sqlplus. So in general the instantclient does not need PATH. HTH! |
From: Anthony T. <ant...@gm...> - 2006-10-16 14:11:33
|
This is a common issue. The cgi script does __not__ have the same environment as your console/x-term does. Setting the environment variable ORACLE_HOME is thus necessary one way or the other before starting to use the Oracle client. There are a number of other messages to this list that indicate what you did is (one of) the correct solution(s). On 10/16/06, M. A. Wani <maw...@gm...> wrote: > Hi All, > > i am executing python script as cgi, path of this script is in html page > but got error > RuntimeError: Unable to acquire Oracle environment handle > > (i solve this error , but not sure is this proper way) > > funny thing is > i used sqlplus "user/password@connection" > it worked fine > got sql> prompt > > > then i wrote a script file test.py > > import cx_Oracle > db = cx_Oracle.connect("user/password@connection") > cur = db.cursor() > cur.execute("select * from emp") > r = cur.fetchall() > for i in r: > print i > > > it also worked fine, i thought my environment is proper. > > > then i wrote cgi-script > > #!/usr/bin/python > print 'content-type: text/html','\n'; > import cgi > import sys > import cx_Oracle > import os > sys.stderr = sys.stdout > db = cx_Oracle.connect('mukhtar/mukhtar@navi') > > but got error on browser (RuntimeError: Unable to acquire Oracle > environment handle ) > > then explicitly I set ORACLE_HOME in script itself, it worked > > #!/usr/bin/python > print 'content-type: text/html','\n'; > > import cgi > import sys > import cx_Oracle > import os > sys.stderr = sys.stdout > os.putenv('ORACLE_HOME','/u01/app/oracle/product/9.2.0') > # i just add this line, > db = cx_Oracle.connect('mukhtar/mukhtar@navi') > > > but got confused it ORACLE_HOME is set and working with normal script, why > i need to put this line in cgi-script > > Thanks in Advance, > Mukhtar > > > > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job > easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > > _______________________________________________ > cx-oracle-users mailing list > cx-...@li... > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > > > |