Bad file descriptor when connecting to oracle database using python-oracledb

289 views Asked by At

I am trying to connect to a remote oracle database using python's oracledb driver and the following simply script to test my connection:

import oracledb


username = 'placeholder'
password = 'placeholder'
hostname = 'placeholder'
port = 1521
service_name = 'placeholder'
dsn = oracledb.makedsn(hostname, port, service_name=service_name)

connection =  oracledb.connect(user=username, password=password, dsn=dsn)

print("Successfully connected to Oracle Database")
connection.close()

I am getting the following error:

Traceback (most recent call last):
  File "src/oracledb/impl/thin/connection.pyx", line 328, in oracledb.thin_impl.ThinConnImpl.connect
  File "src/oracledb/impl/thin/connection.pyx", line 215, in oracledb.thin_impl.ThinConnImpl._connect_with_params
  File "src/oracledb/impl/thin/connection.pyx", line 186, in oracledb.thin_impl.ThinConnImpl._connect_with_description
  File "src/oracledb/impl/thin/connection.pyx", line 127, in oracledb.thin_impl.ThinConnImpl._connect_with_address
  File "src/oracledb/impl/thin/protocol.pyx", line 251, in oracledb.thin_impl.Protocol._connect_phase_two
  File "src/oracledb/impl/thin/protocol.pyx", line 381, in oracledb.thin_impl.Protocol._process_message
  File "src/oracledb/impl/thin/protocol.pyx", line 359, in oracledb.thin_impl.Protocol._process_message
  File "src/oracledb/impl/thin/protocol.pyx", line 430, in oracledb.thin_impl.Protocol._receive_packet
  File "src/oracledb/impl/thin/packet.pyx", line 561, in oracledb.thin_impl.ReadBuffer.receive_packet
  File "src/oracledb/impl/thin/packet.pyx", line 360, in oracledb.thin_impl.ReadBuffer._receive_packet_helper
  File "src/oracledb/impl/thin/packet.pyx", line 206, in oracledb.thin_impl.ReadBuffer._get_data_from_socket
  File "/opt/homebrew/lib/python3.11/site-packages/oracledb/errors.py", line 127, in _raise_err
    raise exc_type(_Error(message)) from cause
oracledb.exceptions.DatabaseError: DPY-4011: the database or network closed the connection

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/mitchellgrant/jist-data-pipeline/jist_dbt/test.py", line 11, in <module>
    connection =  oracledb.connect(user=username, password=password, dsn=dsn)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/oracledb/connection.py", line 1020, in connect
    return conn_class(dsn=dsn, pool=pool, params=params, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/oracledb/connection.py", line 130, in __init__
    impl.connect(params_impl)
  File "src/oracledb/impl/thin/connection.pyx", line 337, in oracledb.thin_impl.ThinConnImpl.connect
  File "src/oracledb/impl/thin/connection.pyx", line 235, in oracledb.thin_impl.ThinConnImpl._force_close
  File "src/oracledb/impl/thin/protocol.pyx", line 353, in oracledb.thin_impl.Protocol._force_close
OSError: [Errno 9] Bad file descriptor

I have tried a few different workarounds to no avail. Does anyone here have any suggestions for me?

Thanks :)

1

There are 1 answers

0
Anthony Tuininga On

The first error reported (oracledb.exceptions.DatabaseError: DPY-4011: the database or network closed the connection) is the one that matters. It is highly likely that your database is using NNE. Take a look at the troubleshooting documentation in order to confirm that.

As an aside, the second error reported is a bug and has been fixed in the repository and will be available in version 2.0 when it is released. In addition, when the error DPY-4011 is raised a link to the above documentation is also included in the message. This enhancement will also be available in version 2.0 when it is released.