英文:
Pandas.read_sql throw exception from sqlalchemy: AttributeError: 'Connection' object has no attribute 'exec_driver_sql'
问题
#pd.__version__ is '2.0.2'
#sqlalchemy.__version__ is '1.3.7'
import pandas as pd
from sqlalchemy import create_engine
conn_str = 'connection_string'
engine = create_engine(conn_str)
Yesterday everything was fine and worked but today,
when I call
`pd.read_sql(ANY_QUERY, con=engine)` I get an exception:
~/anaconda3/lib/python3.9/site-packages/pandas/io/sql.py in read_sql(sql, con, index_col, coerce_float, params, parse_dates, columns, chunksize, dtype_backend, dtype)
661 )
662 else:
--> 663 return pandas_sql.read_query(
664 sql,
665 index_col=index_col,
~/anaconda3/lib/python3.9/site-packages/pandas/io/sql.py in read_query(self, sql, index_col, coerce_float, parse_dates, params, chunksize, dtype, dtype_backend)
1736
1737 """
-> 1738 result = self.execute(sql, params)
1739 columns = result.keys()
1740
~/anaconda3/lib/python3.9/site-packages/pandas/io/sql.py in execute(self, sql, params)
1560 args = [] if params is None else [params]
1561 if isinstance(sql, str):
-> 1562 return self.con.exec_driver_sql(sql, *args)
1563 return self.con.execute(sql, *args)
1564
AttributeError: 'Connection' object has no attribute 'exec_driver_sql'
The solution is to add to engine `.raw_connection()` -> `engine.raw_connection()`
**But what is happening? I did nothing, no new libs, no lib updates.
Could anyone please explain me.**
英文:
#pd.version is '2.0.2'
#sqlalchemy.version is '1.3.7'
import pandas as pd
from sqlalchemy import create_engine
conn_str = 'connection_string'
engine = create_engine(conn_str)
Yesterday everything was fine and worked but today,
when I call
pd.read_sql(ANY_QUERY, con=engine)
I get an exception:
~/anaconda3/lib/python3.9/site-packages/pandas/io/sql.py in read_sql(sql, con, index_col, coerce_float, params, parse_dates, columns, chunksize, dtype_backend, dtype)
661 )
662 else:
--> 663 return pandas_sql.read_query(
664 sql,
665 index_col=index_col,
~/anaconda3/lib/python3.9/site-packages/pandas/io/sql.py in read_query(self, sql, index_col, coerce_float, parse_dates, params, chunksize, dtype, dtype_backend)
1736
1737 """
-> 1738 result = self.execute(sql, params)
1739 columns = result.keys()
1740
~/anaconda3/lib/python3.9/site-packages/pandas/io/sql.py in execute(self, sql, params)
1560 args = [] if params is None else [params]
1561 if isinstance(sql, str):
-> 1562 return self.con.exec_driver_sql(sql, *args)
1563 return self.con.execute(sql, *args)
1564
AttributeError: 'Connection' object has no attribute 'exec_driver_sql'
The solution is to add to engine .raw_connection()
-> engine.raw_connection()
But what is happening? I did nothing, no new libs, no lib updates.
Could anyone please explain me.
答案1
得分: 2
我刚遇到了和你一样的问题。
这是我得到的信息:Pandas需要版本1.4.16
或更新的sqlalchemy
(当前安装的版本是1.3.24
)。
也许升级你的sqlalchemy
版本会有帮助。
英文:
I've just had the same problem as you.
This is how I'm informed: Pandas requires version 1.4.16
or newer of sqlalchemy
(version 1.3.24
currently installed)
Maybe upgrading your sqlalchemy
version may help.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论