AWS RDS oracle python 连接
AWS RDS oracle python connection
我启动了一个 RDS Oracle 数据库实例并想使用 python 代码连接它。我使用 cx_oracle 做了一些事情,但没有成功。
任何建议/帮助都会很棒!
提前致谢
import cx_Oracle
connstr = 'username/password@testinstance.cycxmhpviuwu.eu-west-1.rds.amazonaws.com:1521/orcl'
conn = cx_Oracle.connect(connstr)
我收到的错误消息是:
cx_Oracle.DatabaseError: DPI-1047: 32-bit Oracle Client library cannot be loaded: "The specified module could not be found"
您需要 (a) 安装 32 位 Oracle Client 库或 (b) 确保您使用的是 64 位 Python 和 64 位 cx_Oracle。有关详细信息,请参阅 installation instructions。
请检查,32 位/64 位库,以及 Installation Guide
此外,您可以参考下面的代码片段
from __future__ import print_function
import cx_Oracle
import boto3
import base64
import requests
import json
import configparser
def connect_oracle(oracle_arn,oracle_host,oracle_port,oracle_db):
session = boto3.session.Session()
client = session.client('secretsmanager','us-west-2')
response = client.get_secret_value(SecretId=oracle_arn)
data = json.loads(response['SecretString'])
dsn_tns = cx_Oracle.makedsn(oracle_host,oracle_port,oracle_db)
conn = cx_Oracle.connect(data['username'],data['password'],dsn_tns)
return conn
def test_oracle_connect():
#change the variable value as required
oracle_arn = 'oracle_arn'
oracle_host = 'oracle_host'
oracle_port = 'oracle_port'
oracle_db = 'oracle_db'
run_rds_test_scripts = 'true'
if run_rds_test_scripts == 'true':
conn = connect_oracle(oracle_arn,oracle_host,oracle_port,oracle_db)
cur = conn.cursor()
executed = cur.execute('select count(*) from dba_tables')
res = cur.fetchmany(numRows=1)
row_number = len(res)
assert row_number == 1
cur.close()
conn.close()
else:
print('no run')
test_oracle_connect()
我启动了一个 RDS Oracle 数据库实例并想使用 python 代码连接它。我使用 cx_oracle 做了一些事情,但没有成功。 任何建议/帮助都会很棒!
提前致谢
import cx_Oracle
connstr = 'username/password@testinstance.cycxmhpviuwu.eu-west-1.rds.amazonaws.com:1521/orcl'
conn = cx_Oracle.connect(connstr)
我收到的错误消息是:
cx_Oracle.DatabaseError: DPI-1047: 32-bit Oracle Client library cannot be loaded: "The specified module could not be found"
您需要 (a) 安装 32 位 Oracle Client 库或 (b) 确保您使用的是 64 位 Python 和 64 位 cx_Oracle。有关详细信息,请参阅 installation instructions。
请检查,32 位/64 位库,以及 Installation Guide
此外,您可以参考下面的代码片段
from __future__ import print_function
import cx_Oracle
import boto3
import base64
import requests
import json
import configparser
def connect_oracle(oracle_arn,oracle_host,oracle_port,oracle_db):
session = boto3.session.Session()
client = session.client('secretsmanager','us-west-2')
response = client.get_secret_value(SecretId=oracle_arn)
data = json.loads(response['SecretString'])
dsn_tns = cx_Oracle.makedsn(oracle_host,oracle_port,oracle_db)
conn = cx_Oracle.connect(data['username'],data['password'],dsn_tns)
return conn
def test_oracle_connect():
#change the variable value as required
oracle_arn = 'oracle_arn'
oracle_host = 'oracle_host'
oracle_port = 'oracle_port'
oracle_db = 'oracle_db'
run_rds_test_scripts = 'true'
if run_rds_test_scripts == 'true':
conn = connect_oracle(oracle_arn,oracle_host,oracle_port,oracle_db)
cur = conn.cursor()
executed = cur.execute('select count(*) from dba_tables')
res = cur.fetchmany(numRows=1)
row_number = len(res)
assert row_number == 1
cur.close()
conn.close()
else:
print('no run')
test_oracle_connect()