问题描述
我正在使用 cx_Oracle 在 Python 中建立与 Oracle 数据库的连接。我正在使用钱包连接到数据库。并且代码在虚拟环境中运行。 当我激活虚拟环境并手动运行脚本时,它运行良好。但是在运行表单 crontab 或 Tidal(调度程序)时会引发以下错误:
cx_Oracle.DatabaseError: ORA-12578: TNS:wallet open Failed
之前我遇到了另一个类似的问题:
cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so"
- 手动运行时工作正常,但使用 crontab 时出错,已通过包含 this answer 中的建议行解决此问题。
下面是定时任务:
0 6 * * * cd /path/to/the/code && /path/to/the/venv/myEnv/bin/python /path/script.py
代码如下:
#!/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()
请注意,用户名/密码连接在命令行和 crontab 中都有效, 但是对于 Wallet 字符串,它只能从命令行运行,并在 crontab 中引发以下错误:
cx_Oracle.DatabaseError: ORA-12578: TNS:wallet open Failed
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)