oracle / python-oracledb

Python driver for Oracle Database conforming to the Python DB API 2.0 specification. This is the renamed, new major release of cx_Oracle

Home Page:https://oracle.github.io/python-oracledb

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to make a connection via Thin Mode

meenmo opened this issue · comments

OS: Windows 10 Pro
Python Version: 3.11.4 (64-bit)
oracledb Module Version: 2.1.0
Oracle Client Version: 12.2.0 (installed both 32-bit and 64-bit versions)
Environment: Working at a corporate without an internet connection
Issue Description:
I am able to successfully connect to the Oracle database using the Thick mode with the following Python code:

import oracledb

oracledb.init_oracle_client()
conn=oracledb.connect(user='user_id', password='000000', dsn='xx.x.xxx.xx:0000/SERVICE')

However, thin mode returns the following error:

import oracledb

conn=oracledb.connect(user='user_id', password='000000', dsn='xx.x.xxx.xx:0000/SERVICE')

Traceback (most recent call last):
File "src\oracledb\impl/thin/connection.pyx", line 279, in oracledb.thin_impl.ThinConnImpl._connect_with_address
File "src\oracledb\impl/thin/protocol.pyx", line 241, in oracledb.thin_impl.Protocol._connect_phase_one
File "src\oracledb\impl/thin/protocol.pyx", line 404, in oracledb.thin_impl.Protocol._process_message
File "src\oracledb\impl/thin/protocol.pyx", line 382, in oracledb.thin_impl.Protocol._process_message
File "src\oracledb\impl/thin/protocol.pyx", line 453, in oracledb.thin_impl.Protocol._receive_packet
File "src\oracledb\impl/thin/packet.pyx", line 705, in oracledb.thin_impl.ReadBuffer.wait_for_packets_sync
File "src\oracledb\impl/thin/transport.pyx", line 318, in oracledb.thin_impl.Transport.read_packet
File "C:\Program Files\Python\Lib\site-packages\oracledb\errors.py", line 181, in _raise_err
raise error.exc_type(error) from cause
oracledb.exceptions.DatabaseError: DPY-4011: the database or network closed the connection
Help: https://python-oracledb.readthedocs.io/en/latest/user_guide/troubleshooting.html#dpy-4011

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "", line 1, in
File "C:\Program Files\Python\Lib\site-packages\oracledb\connection.py", line 1158, in connect
return conn_class(dsn=dsn, pool=pool, params=params, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python\Lib\site-packages\oracledb\connection.py", line 541, in init
impl.connect(params_impl)
File "src\oracledb\impl/thin/connection.pyx", line 381, in oracledb.thin_impl.ThinConnImpl.connect
File "src\oracledb\impl/thin/connection.pyx", line 377, in oracledb.thin_impl.ThinConnImpl.connect
File "src\oracledb\impl/thin/connection.pyx", line 337, in oracledb.thin_impl.ThinConnImpl._connect_with_params
File "src\oracledb\impl/thin/transport.pyx", line 318, in oracledb.thin_impl.Transport.read_packet
File "src\oracledb\impl/thin/connection.pyx", line 284, in oracledb.thin_impl.ThinConnImpl._connect_with_address
File "C:\Program Files\Python\Lib\site-packages\oracledb\errors.py", line 181, in _raise_err
raise error.exc_type(error) from cause
oracledb.exceptions.OperationalError: DPY-6005: cannot connect to database (CONNECTION_ID=U5K1A/B/wLGbe4TC4sn5uw==).
DPY-4011: the database or network closed the connection
Help: https://python-oracledb.readthedocs.io/en/latest/user_guide/troubleshooting.html#dpy-4011

@cjbj Thank you for your comment!

My ultimate goal is to utilize the recently released aysnc feature.

According to this article, thick mode will not support asyncio. Changing to TLS is not an option for me, as I am not a server-side DBA.

Is there currently no way to use async?

Thick mode cannot support asyncio as there is no direct access to the socket, so no way to handle events from I/O. And thin mode doesn't support NNE currently. So at the moment you cannot use asyncio with that database, unfortunately. Although you could use a thread pool to make use of asyncio manually my own experiments with that have shown that the performance is much worse than the normal synchronous approach -- so not much point in doing so!

Closing as answered - we recognize the issues that are pain points.