Pandas.read_sql throw exception from sqlalchemy: AttributeError: 'Connection' object has no attribute 'exec_driver_sql'

huangapple go评论104阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年6月9日 12:00:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76437122.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定