Search code examples
pythonpython-3.xoracle19cpython-oracledb

Oracle 19c connection with python Listener refused connection


I'm using oracledb library as the cx_oracle is not working now, using the command oracledb.connect(), and it always gives error

here is my code:

connection = oracledb.connect(
     user='myusername',
     password='mypassword',
     dsn='xx.xx.xxx.xxx:portnumber/dsnname')
print("Successfully connected to Oracle Database")

oracledb.exceptions.OperationalError: DPY-6000: cannot connect to database. Listener refused connection. (Similar to ORA-12660)

and if I set the parameters like this

connection = oracledb.connect(
     user='myusername',
     password='mypassword',
     dsn='xx.xx.xxx.xxx:portnumber:dsnname')
print("Successfully connected to Oracle Database")

it returns error

oracledb.exceptions.DatabaseError: DPY-4027: no configuration directory to search for tnsnames.ora

the database administrator approved the variables are correct and we are using thin client which is the default in the code parameters so I don't know what is making the problem?


Solution

  • The error (ORA-12660) indicates that you have encryption or checksumming parameters set on the database. These are set up in the server side sqlnet.ora and look something like this:

    SQLNET.ENCRYPTION_SERVER=REQUIRED
    SQLNET.CRYPTO_CHECKSUM_SERVER=REQUIRED
    SQLNET.ENCRYPTION_TYPES_SERVER=(AES256,AES192,AES128)
    SQLNET.CRYPTO_CHECKSUM_TYPES_SERVER=(SHA1)
    SQLNET.ENCRYPTION_CLIENT=REQUIRED
    SQLNET.CRYPTO_CHECKSUM_CLIENT=REQUIRED
    SQLNET.ENCRYPTION_TYPES_CLIENT=(AES256,AES192,AES128)
    SQLNET.CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA1)
    

    This has been noted in the documentation. Your only option is to either disable the server requirement for native network encryption (NNE) or enable thick mode (which works the same way as cx_Oracle).

    You can follow along with this enhancement request to see when NNE support is added to thin mode.