1

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
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
rd10
  • 1,599
  • 2
  • 10
  • 27
  • 1
    Check file permissions and who the cron process is running as. It would be better (ie safer) to set Oracle environment variables like ORACLE_HOME and LD_LIBRARY_PATH in a shell script that then invokes Python - avoid setting variables inside Python. In fact, Linux needs LD_LIBRARY_PATH set before a process starts. – Christopher Jones Jun 28 '21 at 00:14
  • Thanks @ChristopherJones for the comment. I changed to more appropriate user in the scheduler, and it works fine now. Didn't even have to set Oracle environment variables like ORACLE_HOME in the script now. I have one more job running from crontab that was also having same issue, will check that also and update. – rd10 Jun 29 '21 at 14:36
  • Hi, so for the cron job the issue is still there. I have given full permissions to all related files. Files were created with a super user which is also the one running crontab. Also tried to set Oracle environment variables in a wrapper shell script and invoking python script. Still getting the same wallet open error. Any suggestions? – rd10 Jul 06 '21 at 21:26

1 Answers1

0

what helped on our end was to broaden permissions on the oracle wallet files. Locate your oracle wallet files and do 'chmod 750 *wallet*' so that other users of the same user group can read the files.