首页 > 解决方案 > 如何修复:cx_Oracle.DatabaseError: ORA-12578: TNS:wallet open failed

问题描述

我正在使用 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 出错,通过包含此答案中的建议行已解决。

下面是cronjob:

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

标签: pythonpython-3.xcx-oracleoracle-wallet

解决方案


对我们有所帮助的是扩大了对预言机钱包文件的权限。找到您的 oracle 钱包文件并执行“chmod 750 *wallet*”,以便同一用户组的其他用户可以读取这些文件。


推荐阅读