Public Key Authentication and cx_Oracle Using Python

I searched a little Google, but I did not find significant results. Is it possible to use key-based authentication to connect to an Oracle server using Python? My goal is to automate some of the reports that I make with Python, without having to store the username and password anywhere on the server.

+3
source share
2 answers

One possible solution is the introduction of Oracle Wallet. Creating an entry in Oracle Wallet includes:

  • tnsname permission name set for the specified instance
  • username and password

: Oracle sid, , ORCL, , , my_user. tnsnames.ora , /sid ORCL, :

#initial local name entry:
ORCL = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = my_ip)(PORT = 1528))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ORCL)))

#create an additional local name entry:
ORCL_MY_USER = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = my_ip)(PORT = 1528))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ORCL)))

ORCL_MY_USER. , python script .

:

import cx_Oracle

db = cx_Oracle.connect( "/@ORCL_MY_USER" )

cursor = db.cursor()

r = cursor.execute( "SELECT , , account_status, default_tablespace, time_tablespace dba_users order by username" )

, , account_status, default_tablespace, time_tablespace :

    print username, '\t', password, '\t', account_status, '\t', default_tablespace, '\t', temporary_tablespace
+4

, Oracle sqlnet.ora.

WALLET_LOCATION = (SOURCE = (METHOD = FILE) (METHOD_DATA = (DIRECTORY = /u01/app/oracle/product/11.2.0.2/dbhome_1/owm/wallets/oracle)))
SQLNET.WALLET_OVERRIDE = TRUE
SSL_CLIENT_AUTHENTICATION = FALSE
SSL_VERSION = 0

, Oracle $ORACLE_HOME/owm/wallets/.

+1

All Articles