1

I wanted to set the environment variables in the unix for my python scrippting project that uses cx_Oracle to connect with the database and have CRUD operations.

i have used os.environ to set the environment variables for oracle. all the libraries are present in the corresponding directory.

This is the method i have used to set the environment variables is unix

def set_environment():
    os.environ["TNS_ADMIN"]="/opt/oracle/orafmw/product/11.2.0.1/client_1/network/admin"
    os.environ["ORACLE_HOME"] = "opt/oracle/orafmw/product/11.2.0.1/client_1"
    os.environ["LD_LIBRARY_PATH"] = "/opt/oracle/orafmw/product/11.2.0.1/client_1/lib"
    os.environ["PATH"] = "$PATH:/opt/oracle/orafmw/product/11.2.0.1/client_1/bin:."

and i have called the method from the main method of my script.

def get_connect_string():
    return db_username+'/'+password+'@'+host+':'+port+'/'+service_name

def main():
    import os
    import cx_Oracle
    set_environment()
    query = "SELECT * FROM SITE WHERE SITE_CODE = :1"
    try:
        connect_string = get_connect_string()
        conn = cx_Oracle.connect(connect_string)
        cur = conn.cursor()
        d = cur.execute(query, ["AUS"]).fetchone()
        conn.commit()
        if d:
            data = (([i[0] for i in cur.description]), d)
        else:
            data = None
    except Exception as e:
        print("error in operation : ", e)
        conn.rollback()
    finally:
        conn.close()
        print(data)

The error message i am getting is:

Error while trying to retrieve text for error ORA-01804
  • How are you calling Oracle? None of the code in your question would seem to directly produce this error. Do you get a traceback? – tripleee Apr 20 '19 at 20:39
  • i just added the rest of the code – shreeram chaulagain Apr 21 '19 at 02:07
  • Possible duplicate of https://stackoverflow.com/questions/12837811/error-while-trying-to-retrieve-text-for-error-ora-01804 – tripleee Apr 21 '19 at 06:20
  • I have these files in this location. product/11.2.0.1/client_1/oracore/zoneinfo$ Do you think its a timezone related problem? ``` readme.txt timezdif.csv timezlrg_6.dat timezlrg_5.dat timezlrg_4.dat timezlrg_3.dat timezlrg_2.dat timezlrg_1.dat timezlrg_11.dat timezlrg_10.dat timezone_9.dat timezone_8.dat timezone_7.dat timezone_6.dat timezone_5.dat timezone_4.dat timezone_3.dat timezone_2.dat timezone_1.dat timezone_11.dat timezone_10.dat timezlrg_9.dat timezlrg_8.dat timezlrg_7.dat ``` – shreeram chaulagain Apr 21 '19 at 22:23
  • Possible duplicate of [Error while trying to retrieve text for error ORA-01804](https://stackoverflow.com/questions/12837811/error-while-trying-to-retrieve-text-for-error-ora-01804) – recnac Apr 25 '19 at 00:41

1 Answers1

0

The LD_LIBRARY_PATH environment variable cannot be set from within your application. It must be set before the process is started! Otherwise, it will not take effect. The error you are getting indicates that the environment isn't set properly. Try setting the environment variables before running your script and see if that resolves the issue for you!

Anthony Tuininga
  • 6,388
  • 2
  • 14
  • 23