I’m having trouble with cx_Oracle.connect when using 2 different TNS_ADMIN places. I’ve reproduced the problem in a small test script, which switches TNS_ADMIN, makes a wallet connection ; restores TNS_ADMIN, and then attempts to make a second connection to a different DB, which fails.
needTnsSwitch = True
makeWalletCxn = True
username = "*****"
password = "******"
service = "*********"
encoding = "UTF-8"
if needTnsSwitch:
saveTns = os.environ["TNS_ADMIN"]
walletTns = os.environ["WALLET_ADMIN_TNS"]
os.environ["TNS_ADMIN"] = walletTns
if makeWalletCxn:
wcxn = cx_Oracle.connect ("/@*****")
wcxn.close()
os.environ["TNS_ADMIN"] = saveTns
otherCxn = cx_Oracle.connect (username, password, service, encoding = encoding)
With both Booleans True, the 2nd connect fails with:
> ./test-TnsSwitch
Traceback (most recent call last):
File "./test-TnsSwitch", line 25, in <module>
otherCxn = cx_Oracle.connect (username, password, service, encoding = encoding)
cx_Oracle.DatabaseError: ORA-12154: TNS:could not resolve the connect identifier specified
If I set makeWalletCxn to False, or needTnsSwitch to False, the connection assigned to “otherCxn” works fine.
> ./test-TnsSwitch
otherCxn: <cx_Oracle.Connection to *****@*******>
So it would appear that the 1st connect is changing/setting something internally in cx_Oracle which affects the second connection attempt, even though TNS_ADMIN has been restored to its original value.
Any ideas? Is this a bug in cx_Oracle?
thanks