这是文件con = cx_Oracle.connect('/@database_name')
中的代码。
这是为了使用我的oracle钱包而设置的,但由于某种原因(拒绝登录(,它不起作用。如何在这行代码中输入我的用户名和密码?con = cx_Oracle.connect('/@database_name')
您应该看看
https://cx-oracle.readthedocs.io/en/latest/user_guide/connection_handling.html#establishing-数据库连接
要使用带有cx_Oracle的钱包,首先需要配置钱包,创建sqlnet.ora和tnsnames.ora文件,然后需要使用dsn属性
connection = cx_Oracle.connect(dsn="mynetalias", encoding="UTF-8")
其中mynetalias是tnsnames.ora 中的TNS条目
mynetalias =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = yourhost )(PORT = yourport))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = yourservicename)
)
)
请确保已将sqlnet.ora配置为使用钱包
WALLET_LOCATION =
(SOURCE =
(METHOD = FILE)
(METHOD_DATA =
(DIRECTORY = /your_wallet_path_directory)
)
)
SQLNET.WALLET_OVERRIDE = TRUE
您可以使用以下
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)