Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
353 views
in Technique[技术] by (71.8m points)

python - SQLAlchemy Oracle - InvalidRequestError: could not retrieve isolation level

I am having problems accessing tables in an Oracle database over a SQLAlchemy connection. Specifically, I am using Kedro catalog.load('table_name') and getting the error message Table table_name not found. So I decided to test my connection using the method listed in this answer: How to verify SqlAlchemy engine object.

from sqlalchemy import create_engine
engine = create_engine('oracle+cx_oracle://USER:PASSWORD@HOST:PORT/?service_name=SERVICE_NAME')
engine.connect()

Error: InvalidRequestError: could not retrieve isolation level

I have tried explicitly adding an isolation level as explained in the documentation like this:

engine = create_engine('oracle+cx_oracle://USER:PASSWORD@HOST:PORT/?service_name=SERVICE_NAME', execution_options={'isolation_level': 'AUTOCOMMIT'})

and this:

engine.connect().execution_options(isolation_level='AUTOCOMMIT')

and this:

connection = engine.connect()
connection = connection.execution_options(
    isolation_level="AUTOCOMMIT"
)

but I get the same error in all cases.

question from:https://stackoverflow.com/questions/65830524/sqlalchemy-oracle-invalidrequesterror-could-not-retrieve-isolation-level

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The Oracle database only supports READ COMMITTED, SERIALIZABLE or AUTOCOMMIT as isolation level.

Use the following for the isolation level for the connection:

connection = engine.connect()
connection = connection.execution_options(
    isolation_level="AUTOCOMMIT"
)

For READ COMMITTED and SERIALIZABLE, the Oracle dialect sets the level at the session level using ALTER SESSION, which is reverted back to its default setting when the connection is returned to the connection pool.

See the docs for more details.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...