cx_Oracle: How do I connect to Oracle when you use a Wallet?

5.8k views Asked by At

Here is the code in the file con = cx_Oracle.connect('/@database_name').

This is setup to use my oracle wallet but its not working for some reason (giving me login denied). How do I enter my user name and password in this line of code? con = cx_Oracle.connect('/@database_name')

2

There are 2 answers

0
Roberto Hernandez On

You should take a look on

https://cx-oracle.readthedocs.io/en/latest/user_guide/connection_handling.html#establishing-database-connections

To use a wallet with cx_Oracle, you need first to configure the wallet, create the sqlnet.ora and tnsnames.ora files, and you need to use the dsn property

connection = cx_Oracle.connect(dsn="mynetalias", encoding="UTF-8")

Where mynetalias is the TNS entry in your tnsnames.ora

mynetalias =
(DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = yourhost )(PORT = yourport))
    (CONNECT_DATA =
        (SERVER = DEDICATED)
        (SERVICE_NAME = yourservicename)
    )
)

Be sure to have the sqlnet.ora configured for using the wallet

WALLET_LOCATION =
(SOURCE =
    (METHOD = FILE)
    (METHOD_DATA =
        (DIRECTORY = /your_wallet_path_directory)
    )
)
SQLNET.WALLET_OVERRIDE = TRUE
1
Jim Macaulay On

You can use below,

import cx_Oracle
ip = '192.168.0.1'
port = 1521
service_name = 'my_service'
dsn = cx_Oracle.makedsn(ip, port, service_name=service_name)

db = cx_Oracle.connect('user', 'password', dsn)