I am trying to connect with an Oracle 12c database using cx_oracle. My code is listed below:
import cx_Oracle
from cx_Oracle import DatabaseError
import pandas as pd
import credaws
import os
os.system('export ORACLE_HOME=/opt/app/oracle/product/client_12_2')
os.system('export PATH=$ORACLE_HOME/bin:$PATH')
os.system('export LD_LIBRARY_PATH=$ORACLE_HOME/lib')
try:
# cx_Oracle.init_oracle_client(lib_dir=libdir)
dsn_tns=cx_Oracle.makedsn(credaws.host_name,credaws.port_number,service_name=credaws.service_name)
conn = cx_Oracle.connect(user=credaws.user,password=credaws.password,dsn=dsn_tns)
if conn:
cursor = conn.cursor()
print('Connection Successful')
except DatabaseError as e:
err, = e.args
print("Oracle-Error-Code:", err.code)
print("Oracle-Error-Message:", err.message)
finally:
cursor.close()
conn.close()
I'm still getting this error:
Oracle 12c is installed in /opt/app/oracle/product/client_12_2 location. What am I doing wrong?
Edit 1: I setting ORACLE_HOME, PATH and LD_LIBRARY_PATH environment variables before calling cx_oracle connect method. However, still getting the same error.
Edit 2: When running this script as oracle user, I'm getting below error: