I am establishing connection to Oracle database in Python using cx_Oracle. I am using wallet to connect to DB. And the code is running inside virtual env. When I activate the virtual env and run the script manually, it runs fine. But it throws below error when running form crontab or Tidal (a scheduler):
cx_Oracle.DatabaseError: ORA-12578: TNS:wallet open failed
Previously I was facing another similar issue:
cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so"
-working fine with manual run but gives error with crontab, which was resolved by including the suggested line from this answer.
Below is the cronjob:
0 6 * * * cd /path/to/the/code && /path/to/the/venv/myEnv/bin/python /path/script.py
Below is the code:
#!/usr/bin/env python3
import os
import cx_Oracle
os.environ["ORACLE_HOME"]="/u01/app/oracle/product/12.2.0/client64"
def fetch_data():
#connection = cx_Oracle.connect("user", "pwd", "conn")
connection = cx_Oracle.connect(dsn="WALLET_NAME", encoding="UTF-8")
cursor = connection.cursor()
with open('rtp_query.sql') as f:
sql = f.read()
cursor.execute(sql)
result = cursor.fetchall()
cursor.close()
connection.close()
Note that username/pwd connection is working from both command line and crontab, but with Wallet string, it only works from command line, and throws below error for crontab:
cx_Oracle.DatabaseError: ORA-12578: TNS:wallet open failed