Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'OptionEngine' object has no attribute 'execute' [duplicate]

SQLAlchemy v2.0.0 works in a different way - they have changed some of the api.

Following investigation I found a solution. My code was simply:

s_settings_df = pd.read_sql_query(query, engine_cloud)

The error like the title, "AttributeError: 'OptionEngine' object has no attribute 'execute'"

I will answer my own post below.

I tried using various versions but did not like the idea of getting locked with historic components.

like image 816
NAJ Avatar asked Sep 03 '25 04:09

NAJ


1 Answers

Adding the text import:

from sqlalchemy import create_engine, text
engine_cloud = create_engine("mysql+mysqldb://usr:pwd@localhost/dbs") # replace with your parameters
s_settings_df = pd.DataFrame(engine_cloud.connect().execute(text(query)))

I hope that helps someone.

like image 94
NAJ Avatar answered Sep 04 '25 17:09

NAJ