shreeram chaulagain
shreeram chaulagain

Reputation: 11

Error while trying to retrieve text for error ORA-01804 python in unix

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

Upvotes: 1

Views: 8838

Answers (1)

Anthony Tuininga
Anthony Tuininga

Reputation: 7086

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!

Upvotes: 1

Related Questions