Cx_Oracle : DatabaseError: ORA-28040: No matching authentication protocol - python

I am facing this error while using Cx_Oracle package in python environment. I upgraded to oracle 12c from 11g but it still gets me this error. Also, I am using ojdbc6.jar.
DatabaseError: ORA-28040: No matching authentication protocol

From 12c onward, minimum supported version default has changed from 11 to 12 and SQLNET.ALLOWED_LOGON_VERSION is now replaced with the SQLNET.ALLOWED_LOGON_VERSION_SERVER and SQLNET.ALLOWED_LOGON_VERSION_CLIENT parameters
You need to add these two parameters in your sqlnet.ora file, you can find that file at
ORACLE_HOME/network/admin/
After you made the changed, do not forget to reload the listener using lsnrctl reload
For more see Oracle Official Doc

This helped me while using cx-Oracle 8.0.1
add in sqlnet.ora
SQLNET.ALLOWED_LOGON_VERSION_SERVER=11
The error disapears, but I got instead
ORA-01017: Invalid Username/Password
The workaround was to change the password:
alter user UUUUU identified by PWD;
After this the user PASSWORD_VERSIONS were set from 10 to 12 and everything worked fine!
select PASSWORD_VERSIONS from dba_users where username = 'UUUUU';
PASSWORD_VERSIONS
-----------------
10G 11G 12C

ojdbc6.jar is driver for JVM/Java
Cx_Oracle is C/C++ library depending on libclnth.so library.
The errors states that your client is either to old (or too new) and you can not authenticate to the database. There is no auth protocol that both sides implement/accept.
Either you should upgrade your client or change
sqlnet.ora set SQLNET.ALLOWED_LOGON_VERSION to version of your client library.

Related

jupyter-notebook eith oracle connection problem

I have a problem that I've been trying to solve for a very long time and it seems like I'm missing something very basic.
I use a Linux server with Anaconda, Oracle client, Pycharm and jupyter-notebook installed.
I use python scripts in which I write and read data to Oracle DB, and I use the Cx_oracle extension.
The server has several users with a personal username for each and each of them has sudo privileges.
I performed all the installations on the server with sudo privileges.
When I try to connect from the server to Oracle DB I connect properly.
When I connect to Python on the server itself, I connect properly to Oracle DB.
When I connect using Pycharm and I define ORACLE_HOME=/OracleTools/19.0.0/ in the environment variables, I connect properly to the Oracle DB.
My problem starts when I want to use jupyter-notebook
When I try to connect to the DB I get the error -
DatabaseError: Error while trying to retrieve text for error ORA-12715
I noticed when I execute os.environ I see that it is defined for me:
ORACLE_HOME: /OracleTools/19.0.0/bin
and should be
/OracleTools/19.0.0
So I changed using command os.environ['ORACLE_HOME'] = '/OracleTools/19.0.0'
Then I get an error:
DatabaseError: ORA-12715: invalid character set specified
And of course this change is not permanently saved ...
If on the server itself I execute the env command both in the private user and in sudo I see ORACLE_HOME: /OracleTools/19.0.0 and not ORACLE_HOME: /OracleTools/19.0.0/bin
My questions:
Where does the data I get in the os.environ command come from?
How can I edit them permanently ?
Is this even the problem I'm having or should I check something else?
I manage to import cx_oracle, which means that there is no problem of expansion
Thanks!

Connect to Oracle database using python from a Linux server (lxv)

In my local machine
I have created a script in python that retrieves data from an Oracle database.
The connection to the DB is done using cx_Oracle:
con = cx_Oracle.connect (username, password, dbService)
When using SQL developer the connection is established using custom JDBC.
Replicate procedure on a Linux server.
I have created a python virtual environment with cx-Oracle pip installed in it.
I have Oracle Client 19.3.0 installed in the server, and the folder instantclient is in place.
When I try to execute the python script as is I get the following error.
cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle
Client library:
DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so: cannot open shared object file: No such file or directory". See https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html for help
I assumed that the problem was the Oracle path which is not the one that python expected. So, I added this extra line of code pin-pointing the path where the Oracle libraries are located.
cx_Oracle.init_oracle_client(lib_dir=r"/apps/oracle/product/19.3.0/lib")
This leads to a different error:
cx_Oracle.DatabaseError: Error while trying to retrieve text for error
ORA-01804
Any clues?
The answer to my question was indicated by the ORA-1804 message.
According to the Oracle initialization doc: https://cx-oracle.readthedocs.io/en/latest/user_guide/initialization.html#usinginitoracleclient
Note if you set lib_dir on Linux and related platforms, you must still
have configured the system library search path to include that
directory before starting Python.
On any operating system, if you set
lib_dir to the library directory of a full database or full client
installation, you will need to have previously set the Oracle
environment, for example by setting the ORACLE_HOME environment
variable. Otherwise you will get errors like ORA-1804. You should set
this, and other Oracle environment variables, before starting Python,
as shown in Oracle
Even though defining the ORACLE_HOME should be done before starting Python (according to Oracle documentation) it is possible to do so by modifying the python script itself. So before the oracle client initialization command the following commands had to be added:
import os
# Setup Oracle paths
os.environ["ORACLE_HOME"] = '/apps/oracle/product/19.3.0'
os.environ["ORACLE_BASE"] = '/apps/oracle'
os.environ["ORACLE_SID"] = 'orcl'
os.environ["LD_LIBRARY_PATH"] = '/apps/oracle/product/19.3.0/lib'
import cx_Oracle
# Initialize Oracle client
cx_Oracle.init_oracle_client(lib_dir=r"/apps/oracle/product/19.3.0/lib")
The cx_Oracle initialization doc points out that on Linux init_oracle_client() doesn't really do what you think it does. You must still set the system library search path to include the Oracle libraries before the Python process starts.
Do I understand correctly that the machine with Python has both the DB installed and Instant Client??
If you do want Python to use the Instant Client libraries, then set LD_LIBRARY_PATH to its location and do not set ORACLE_HOME.
If you have a full Oracle DB installation on the machine with Python, then you can delete Instant Client. You need to set ORACLE_HOME, LD_LIBRARY_PATH and whatever else is needed before starting Python - in general run source /usr/local/bin/oraenv. This should set the system library search path to include /apps/oracle/product/19.3.0/lib . A code snippet like this (untested) one may help: export ORACLE_SID=ORCLCDB;set ORAENV_ASK=NO; source /usr/local/bin/oraenv. Make sure the Python process has read access to the ORACLE_HOME directory.
The cx_Oracle installation guide discusses all this.

What is necessary to connect Python to Oracle Database

I have been trying to connect Python 3.7.1 to TOAD 11, with a client version 10.2.
When I try running the code below
import cx_Oracle
connection = cx_Oracle.connect('myusername/mypassword#orcl')
cursor = connection.cursor()
querystring = "select * from TABLE_NAME"
cursor.execute(querystring)
I get the following error:
DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "C:\ORACLE\PRODUCT\10.2.0\CLIENT_1\bin\oci.dll is not the correct architecture". See https://oracle.github.io/odpi/doc/installation.html#windows for help
I have been trying to download a 64 bit client, but I don't understand why I need one since TOAD and it's current client are 32-bit. The issue is that with my company, it does not say the bits in the description whenever something is requested to be installed (due to the security in the network, I cannot download anything unless it is approved by the IT department, and it can only be downloaded through their server). I attempted to download the instant client 11g, but it seems it was installed but the 10.2 version it's still the only one I can find in my machine. I cannot see where it is located anywhere, so I cannot even set an environment variable for it, but I can see it in the "uninstall wizard", but it doesn't show it's location. I don't even know if 11g is 64 bit or 32 bit.
Has anybody fixed this problem before?
Is my code off and maybe that's why its not working?
The error message is saying you need a 64-bit Oracle Client because Python is 64-bit.
For cx_Oracle you need Oracle client libraries version 11.2 or later. You can get the libraries as part of Oracle Instant Client from http://www.oracle.com/technetwork/topics/winx64soft-089540.html On Windows you will also need the Redistributable noted on that download page.
Also see the cx_Oracle installation instructions at https://cx-oracle.readthedocs.io/en/latest/installation.html#installing-cx-oracle-on-windows
You will have to work with your IT people to make this happen.

Error when connecting to DB2 with ibm_db with SSL

I am trying to connect to DB2 using python module ibm_db with SSL and I get the following error
conn = ibm_db.connect("DATABASE=myDB;HOSTNAME=xx.xx.xxx.xxx;PORT=nnn;PROTOCOL=TCPIP;SECURITY=SSL;SSLServerCertificate=./myFile.arm;UID=<username>;PWD=<password>;","","")
stmt = ibm_db.exec_immediate(conn, "delete from myschema.mytable")
I get the following exception
Exception: [IBM][CLI Driver] SQL30081N A communication error has been detected. Communication protocol being used: "SSL". Communication API being used: "SOCKETS". Location where the error was detected: "". Communication function detecting the error: "sqlccSSLSocketSetup". Protocol specific error code(s): "414", "*", "*". SQLSTATE=08001 SQLCODE=-30081
I have spent several hours trying to debug. Can't make any progress here
Any help will be appreciated.
Tinniam,
How is your gskit keystore (i.e. .kdb) and stash file (i.e. .sth file - file storing encrypted password for the keystore) created?
Was it creating locally with the same version on the client machine or was it created by someone on other machine that has a different version of gskit?
There is a known gskit incompatibility issue ( http://www-01.ibm.com/support/docview.wss?uid=swg22014693). A stash file generated with version GSKit 8.0.50.69 and newer versions cannot be read by lower version and it will return exactly gskit 414 error.
Check the gskit on where your keystore and stash file are created and the version that the client is using. There is a gsk8ver_64 tool in sqllib/gskit/bin to tell you the version.
If indeed, you have hit the incompatibility issue, you need to either upgrade your client to use the version of Db2 that has gskit on the newer boundary release OR: find an older version of Db2 server such as 10.5 fp9 and generate a new keystore and stash file with the lower version of gskit.
NOTE: newer version of gskit can read stash created by lower version. But stash file created by 8.0.50.69 and newer versions is not readable by gskit version that is lower than 8.0.50.69 release.
Hope this help solve your issue.
Kevin See
Db2 Hybrid Cloud Security Team
I had the same issue today while opening an SSL connection from a Db2 Client to a Db2 server.
SQL30081N with error code 414. Db2 docs pointed to this https://www.ibm.com/support/knowledgecenter/en/SSVJJU_6.3.0/com.ibm.IBMDS.doc/progref506.htm and the hint was
414 – Incorrectly formatted certificate received from partner.
We figured out sometime later, we have just imported the public key of our server into the client trust keyring. Correct is to import only the public keys of the root server and the intermediate server into the client trust store. You do not need to import the server public key (signed by the intermediate server) into the client trust store.
I hope, the original poster has already found a solution and I just wanted to leave here my solution for the next person with the same issue.
I would recommend to investigate how the SSL / TLS communication is configured, how the certificate is managed.
The SSL-specific error is documented as GSKit issue related to certificates. You probably have checked the recommendations for the error SQL30081N. The error SQL30081N even has protocol-specific details for the error codes.

How to get Python clear-text plugin auth working on Windows (using MySQLdb)?

I have a MariaDB 5.5.57-1ubuntu0.14.04.1 installed on Ubuntu Linux 14.04 and configured with the following to authenticate MySQL users using our OpenLDAP infrastructure via PAM:
# cat /etc/mysql/conf.d/ldap.cnf
[mysqld]
pam-use-cleartext-plugin
plugin-load = auth_pam.so
# cat /etc/mysql/conf.d/ssl.cnf
[mysqld]
ssl-cipher = DHE-RSA-AES256-SHA
ssl-ca=/etc/mysql/ssl/ca-cert.pem
ssl-cert=/etc/mysql/ssl/server-cert.pem
ssl-key=/etc/mysql/ssl/server-key.pem
I've created my user in mysql like this:
MariaDB [(none)]> CREATE user 'ldap1'#'%' IDENTIFIED VIA pam;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON test.* TO 'ldap1'#'%' IDENTIFIED VIA pam REQUIRE SSL;
I can authenticate from a remote Linux host doing this:
mysql -u ldap1 -p -h my.server.net --ssl --enable-cleartext-plugin
When I connect from MySQL Workbench on Windows 7 I can tick 'Enable Cleartext Authentication Plugin' under the Advanced tab (Require SSL of course) and authenticate as well there too.
When I run my Python script, I get the error message below. Anyone know a fix or is there a DLL I need to install?
NOTE:The code I'm using was sent to me from an outside developer and not so sure I can share the code so just posting the error output. If this is not a common problem with a known workaround (It's been difficult finding all the right pieces to do this from both Linux and Windows platforms) I can certainly email said developer and ask about posting watered down version of the connect routine. The code does import MySQLdb to establish the DB connection if it matters.

Categories

Resources