python - 如何修复: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
解决方案
对我们有所帮助的是扩大了对预言机钱包文件的权限。找到您的 oracle 钱包文件并执行“chmod 750 *wallet*”,以便同一用户组的其他用户可以读取这些文件。
推荐阅读
- javascript - 未捕获的 TypeError:c.getContext 不是函数
- python-3.x - 抓取并创建新的df
- reactjs - 自定义 Hook - 返回状态和设置状态
- git - 致命:无法访问“...”:请求的 URL 返回错误:403 Using Sourcetree with gitlab
- angular - 如何在角度指令中测试按键事件
- docker - Docker buildkit 实验性停止工作
- php - PHP:HTTP_request2:从发布请求的响应正文中保存文件
- sharepoint - SharePoint API:访问令牌资源无效
- powershell - Powershell查找和替换失败,因为文件被另一个进程使用
- javascript - 如何仅删除在 localStorage 中多次出现的特定数据