Few posts planned for use in expected Hackathons.
We want to use Oracle Autonomous DB (ADB) from Python. Preferably without need to worry about wallets.
Here are 2 links to Oracle documentation:
- About Connecting to an Autonomous Database Instance
- Connect to Autonomous Database Using a Client Application
and a very nice blog by Oracle PM, Sharad Chandran R:
Below is the Connecting Python Without Wallet option guidelines:
Install on the client oracledb for python connection to the DB:
py -m pip install oracledb
if needed
python -m pip install oracledb --upgrade
Under Network of ADB update the Access type:
You can select “add my IP address” (or input addresses manually, separated by comma.)If you prefer no security at all you can set CIDR Block with value 0.0.0.0/0
Next under the same Network entry in ADB, in Network / Mutual TLS (mTLS) authentication, Uncheck the "Required" check-mark.
In Python, copy the low connection string, from database connection, into the bellow described “cs” variable add ‘’’ before and after the connection as described below. Run the 3 script lines:
import oracledb
cs='''(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=adb.eu-frankfurt-1.oraclecloud.com))(connect_data=(service_name=q4gsn76smrbsdns_badp4sba1ab3ut26_low.adb.oraclecloud.com))(security=(ssl_server_dn_match=yes)))'''
connection=oracledb.connect(user="DB_USER_NAME", password="USER_PASSWORD", dsn=cs)
The important part is the connection.
As I said, we insert the value of Oracle connection string we copied to the cs variable.
For those who worry about hacking, the above described DB does not exist anymore.
No comments:
Post a Comment