【发布时间】:2018-11-07 19:31:21
【问题描述】:
我正在尝试使用 lambda 和 python 使用 cx_oracle 包连接到 rds 上的 oracle 但我明白了:
ORA-21561:OID 生成失败:DatabaseError。
即使在使用 lambda-server-name localhost 添加文件 /tmp/HOSTALIASES 之后。还将HOSTALIASES 添加到lambda 环境变量。引用自:AWS Python Lambda with Oracle - OID Generation Failed。
如何在 aws lambda
中解决此 OID 生成问题这是我的代码
import cx_Oracle
import os
import sys
import time
# sys.path.append('lib')
# os.environ['ORACLE_SID'] = 'DEVDB'
with open('/tmp/HOSTALIASES', 'w') as hosts_file:
hosts_file.write('{} localhost\n'.format(os.uname()[1]))
def orcl_fetch_records(event, context):
# print (sys.path)
# print (os.listdir(os.getcwd()))
# print (os.environ['LD_LIBRARY_PATH'])
# print (os.environ['ORACLE_HOME'])
# print (sys.path)
print (os.environ['HOSTALIASES'])
with open('/tmp/HOSTALIASES', 'r') as hosts_file:
print hosts_file.read()
dsn = cx_Oracle.makedsn("aws-rds-oracle-server-name", "1521", "SID")
print (dsn)
conn = cx_Oracle.connect("username", "password", dsn)
print ("Oracle DB version = " + conn.version)
cur = conn.cursor()
cur.execute('select * from lambda_test')
for result in cur:
print (result)
cur.close()
conn.close()
输出:
ORA-21561:OID 生成失败:DatabaseError Traceback(最近 最后调用):文件“/var/task/orcl_fetch_function.py”,第 25 行,在 orcl_fetch_records conn = cx_Oracle.connect("用户名", "密码", dsn) DatabaseError: ORA-21561: OID 生成失败
【问题讨论】:
-
欢迎来到 SO。 Hoora 完成了巡演和好问题并显示了错误代码(提示:尝试使用“>”,你会得到一个黄色框作为引用的背景)。审查方面没有进一步的cmets。尽情享受吧 ;-)
标签: python oracle amazon-web-services aws-lambda cx-oracle