2

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')

Roberto Hernandez
  • 8,231
  • 3
  • 14
  • 43
  • Some wallets (such as those for Oracle Cloud) are just for encryption and don't have the DB username/password embedded, so you will still need to specify a DB username & password when you connect. Update your question with more detail so we can help. – Christopher Jones Aug 05 '20 at 11:53

2 Answers2

4

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
Roberto Hernandez
  • 8,231
  • 3
  • 14
  • 43
0

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)
Jim Macaulay
  • 4,709
  • 4
  • 28
  • 53