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

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

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

问题

  1. #pd.__version__ is '2.0.2'
  2. #sqlalchemy.__version__ is '1.3.7'
  3. import pandas as pd
  4. from sqlalchemy import create_engine
  5. conn_str = 'connection_string'
  6. engine = create_engine(conn_str)
  7. Yesterday everything was fine and worked but today,
  8. when I call
  9. `pd.read_sql(ANY_QUERY, con=engine)` I get an exception:
  10. ~/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)
  11. 661 )
  12. 662 else:
  13. --> 663 return pandas_sql.read_query(
  14. 664 sql,
  15. 665 index_col=index_col,
  16. ~/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)
  17. 1736
  18. 1737 """
  19. -> 1738 result = self.execute(sql, params)
  20. 1739 columns = result.keys()
  21. 1740
  22. ~/anaconda3/lib/python3.9/site-packages/pandas/io/sql.py in execute(self, sql, params)
  23. 1560 args = [] if params is None else [params]
  24. 1561 if isinstance(sql, str):
  25. -> 1562 return self.con.exec_driver_sql(sql, *args)
  26. 1563 return self.con.execute(sql, *args)
  27. 1564
  28. AttributeError: 'Connection' object has no attribute 'exec_driver_sql'
  29. The solution is to add to engine `.raw_connection()` -> `engine.raw_connection()`
  30. **But what is happening? I did nothing, no new libs, no lib updates.
  31. Could anyone please explain me.**
英文:

#pd.version is '2.0.2'
#sqlalchemy.version is '1.3.7'

  1. import pandas as pd
  2. from sqlalchemy import create_engine
  3. conn_str = 'connection_string'
  4. 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:

  1. ~/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)
  2. 661 )
  3. 662 else:
  4. --> 663 return pandas_sql.read_query(
  5. 664 sql,
  6. 665 index_col=index_col,
  7. ~/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)
  8. 1736
  9. 1737 """
  10. -> 1738 result = self.execute(sql, params)
  11. 1739 columns = result.keys()
  12. 1740
  13. ~/anaconda3/lib/python3.9/site-packages/pandas/io/sql.py in execute(self, sql, params)
  14. 1560 args = [] if params is None else [params]
  15. 1561 if isinstance(sql, str):
  16. -> 1562 return self.con.exec_driver_sql(sql, *args)
  17. 1563 return self.con.execute(sql, *args)
  18. 1564
  19. 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:

确定