oracle / python-cx_Oracle

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

issue while connecting to oracle DB using cx_Oracle #427

Closed skrishnabharat closed 4 years ago

skrishnabharat commented 4 years ago

I am able to connect with Oracle Db using JDBC String in Sql developer but When I tried to connect with DB using cx_Oracle. I'm getting ORA-28759: failure to open file

Cut and paste text showing the command you ran. No screenshots. Use a gist for long screen output and logs: see https://gist.github.com/.

  1. Include a runnable Python script that shows the problem. Include all SQL needed to create the database schema. Use Markdown syntax, see https://help.github.com/github/writing-on-github/basic-writing-and-formatting-syntax

Code:

import cx_Oracle as cx dsn_tns='(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = tcps) (HOST = )(PORT = ))) (CONNECT_DATA = (SERVICE_NAME = ***)))' conn = cx.connect(user=USER, password=PW, dsn=dsn_tns) print(cx.version)

  1. Show the output of:
import sys
import platform

print("platform.platform:", platform.platform())
print("sys.maxsize > 2**32:", sys.maxsize > 2**32)
print("platform.python_version:", platform.python_version())

And:

import cx_Oracle
print("cx_Oracle.version:", cx_Oracle.version)
print("cx_Oracle.clientversion:", cx_Oracle.clientversion())

output: platform.platform: Darwin-18.7.0-x86_64-i386-64bit sys.maxsize > 2**32: True platform.python_version: 3.7.4 cx_Oracle.version: 7.3.0 cx_Oracle.clientversion: (19, 3, 0, 0, 0)

  1. What is your Oracle Database version? 12.2.0.1.0
skrishnabharat commented 4 years ago

As it is TCPS protocol.I have add the sqlnet.ora and tnsnames.ora in the path ⁨instantclient_19_3⁩ \⁨network⁩\admin.

but I still getting the same error.Any Suggestions.

cjbj commented 4 years ago

The common case of this error is that you have wallet files in a non-default location and haven't updated WALLET_LOCATION in sqlnet.ora.

skrishnabharat commented 4 years ago

I can see there is some issue with the sqlnet.ora and tnsnames.ora after updating the files I'm getting new error

ORA-12560: TNS:protocol adapter error

cjbj commented 4 years ago

Give us more details (with private information redacted) - what's in each file and what is your Python code. Are you using a wallet to access Oracle DB? If so, use the connect alias from the tnsnames.ora file instead of hardcoding the connection string like you did in your original post.

skrishnabharat commented 4 years ago

Thanks for your inputs .I ave tred it but still the issue is not resolved. I feel it's due to openssl version. Could you please provide the steps to update openssl version in mac.

(base) HYDHTC7175D:~ krishnabharat.sathi$ openssl version OpenSSL 1.1.1d 10 Sep 2019

https://github.com/oracle/python-cx_Oracle/issues/7

cjbj commented 4 years ago

Without more information about your problem, I wouldn't head down that path.

skrishnabharat commented 4 years ago

sqlnet.ora

wallet_location=(SOURCE=(METHOD=File)(METHOD_DATA=(DIRECTORY=/Users/krishnabharat.sathi/instantclient_19_3/network/admin)))

tnsnames.ora

lgst = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCPS)(Host =** )(Port =**)) ) (CONNECT_DATA = (SERVICE_NAME = ) ) )

code used to connect:

import cx_Oracle as cx conn = cx.connect(user='**', password='**', dsn='lgst') print(conn.version) conn.close()

cjbj commented 4 years ago
adr_base=/tmp/mylogs
diag_adr_enabled=ON
trace_level_client=16

Run mkdir /tmp/mylogs and run SQL*Plus again.

Check the logs in /tmp/mylogs//...//trace/* to see if there is any clue

cjbj commented 4 years ago

Closing - no activity.

exzizt commented 4 years ago

Did you ever solve this? We are having the similar TNS Protocol Adapter error with similar configuration.

anthony-tuininga commented 4 years ago

As @cjbj mentioned, try with SQLPlus first. If you can make it work with SQLPlus getting it to work with cx_Oracle should be easy enough.

exzizt commented 4 years ago

As @cjbj mentioned, try with SQL_Plus first. If you can make it work with SQL_Plus getting it to work with cx_Oracle should be easy enough.

Thanks, I forgot to mention that we are trying with SQL Plus and get the same error message.

cjbj commented 4 years ago

@exzizt then it isn't a cx_Oracle problem :) I recommend you open a new question on OTN or Stackoverflow with all yours details (platforms, versions, whether you have SQLNET.AUTHENTICATION_SERVICES set in a sqlnet.ora file, what does work and what doesn't work etc).

pseudo-sm commented 2 years ago

if you're struggling with this issue and are on a windows system, add the following environment variables oracle_home, oracle_sid and tns_admin (pointing to your oracle_home/network/admin) folder

cjbj commented 2 years ago

For future readers: if you're using Instant Client then don't set those! Also ORACLE_HOME/network/admin is the default network location if cx_Oracle is linked with the libraries in the DB installation so you shouldn't need to set TNS_ADMIN.

ssdittak commented 2 years ago

Fix for Mac

I was able to resolve this by copying sqlnet.ora and tnsnames.ora from the wallet dir to instantclient_19_8/networking/admin dir.

Also, replace the default "?/network/admin" with the actual path of the wallet dir in sqlnet.ora.

Also, used the below:

cx_Oracle.init_oracle_client(lib_dir="instantclient_19_8 path")