oracle / python-cx_Oracle

Python interface to Oracle Database now superseded by python-oracledb
https://oracle.github.io/python-cx_Oracle
Other
890 stars 361 forks source link

How to connect to Oracle database with both username/Password and wallet authentication? #606

Closed tinglixing closed 2 years ago

tinglixing commented 2 years ago
I am using Oracle Client 18 Home 1 SQL Developer platform.platform: Windows-10-10.0.18362-SP0 sys.maxsize > 2**32: True platform.python_version: 3.8.8 cx_Oracle.version: 8.0.1 cx_Oracle.clientversion: (18, 3, 0, 0, 0) I want to connect to Oracle database using cx_Oracle. My Oracle database is using 2 factor authentication, one is username and password, another one is wallet. So after research, I did the code below: ``` import cx_Oracle import os os.environ.get('ORACLE_HOME') os.environ.get('TNS_ADMIN') conn = cx_Oracle.connect(user='user', password='password', dsn='database_name') ``` I got error: DatabaseError: ORA-28759: failure to open file It works for my coworker but I don't know why it doesn't work for me Any insight would be appreciated!
cjbj commented 2 years ago

This is could be because you put sqlnet.ora in a non-default location, and haven't edited the wallet location path inside that file. Either put sqlnet.ora in a default location or edit sqlnet.ora. See the doc I mentioned in https://github.com/oracle/python-cx_Oracle/issues/605

tinglixing commented 2 years ago

My wallet location should be fine. If location has problem, I would not be able to access the database in SQL Developer but I can. Just cannot connect to the database in python.

cjbj commented 2 years ago

That statement may not be valid because SQL Developer almost always uses the Java stack but Python uses a C stack so the implementations are very different. If you share more details we can offer more advice.

tinglixing commented 2 years ago

Thank you! The problem was resolved by updating python and all packages. Now I have a new issue. The code can be ran in command line, i.e. python shell, but it will not run in jupyter and spyder, ides that I have in my Ananconda package. Any idea?

stale[bot] commented 2 years ago

This issue has been automatically marked as inactive because it has not been updated recently. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 2 years ago

This issue has been automatically closed because it has not been updated for a month.