python - 使用 Python 38 从 AWS Lambda 连接 OracleDB 的问题
问题描述
我正在尝试使用 cx_Oracle 库使用 python 访问 lambda 中的 oracle db。由于 oracle 需要 os 特定的客户端来连接,我还下载了即时客户端并将其添加为 AWS 中的一个层。问题是我看到这个不会让步的错误
DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so: cannot open shared object file: No such file or directory"
lambda_handler.py
import cx_Oracle
import os
def lambda_handler(event, context):
dsn = cx_Oracle.makedsn('url', 1521)
con = cx_Oracle.connect(user='user', password='1234', dsn=dsn)
cursor = con.cursor()
cursor.execute('SELECT * FROM DEVICES')
return {
'statusCode': 200,
'body': cursor.fetchall()
}
我已经看到其他线程添加了 init_oracle_client,所以我添加了cx_Oracle.init_oracle_client(lib_dir='/opt/instantclient_21_1')
因为 Lambda 层位于“/opt”目录中,它似乎找到了该文件,但它产生了类似的错误。注意文件不同
DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "libnnz21.so: cannot open shared object file: No such file or directory"
据我了解,由于我专门放置了 lib_dir,因此该文件应该是“/opt/instantclient_21_1/libnnz21.so”,但由于某种原因,Oracle 尝试在当前运行时目录中找到该库。
注意我正在使用:
- 蟒蛇 3.8
- 适用于 Linux x86-64 的 Instant Client Lite
- cx_Oracle-8.1.0-cp39-cp39-manylinux1_x86_64
解决方案
推荐阅读
- r - 如何在 DT 包中居中列?R
- python-3.x - 并行作业任务中的优先级队列
- r - 在 R 中使用带有动态变量的“~ call”
- python - 将子类的实例作为参数传递给其他子类
- c# - Newtonsoft JSON 没有反序列化我的 json 文件中的嵌套对象
- css - 悬停 CSS 上的文本滑入
- flutter - Flutter CupertinoTabBar 显示 CupertinoTabView like Share Page on Instagram
- javascript - 如何获取日期时间选择器并将其转换为服务器格式(toISOString)
- c++ - 找不到 -llibmysqld Collect2.exe:错误:ld 返回 1 个退出状态
- assembly - 如何在 ARM 汇编语言中使用 CPUlator 从用户那里获取输入