I have launched an RDS Oracle database instance and wanted to connect it using a python code. i did something using cx_oracle but not worked out. Any suggestions/ help would be great !
Thanks in Advance
import cx_Oracle
connstr = 'username/password@testinstance.cycxmhpviuwu.eu-west-1.rds.amazonaws.com:1521/orcl'
conn = cx_Oracle.connect(connstr)
Error message I am getting is:
cx_Oracle.DatabaseError: DPI-1047: 32-bit Oracle Client library cannot be loaded: "The specified module could not be found"
You need to either (a) install the 32-bit Oracle Client libraries or (b) ensure that you are using 64-bit Python and 64-bit cx_Oracle. See the installation instructions for more information.
Please check , 32 bit/ 64 bit library , and Installation Guide
Moreover, you can refer to the below code snippet
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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.