当前位置:   article > 正文

AttributeError: ‘OptionEngine‘ object has no attribute ‘execute‘_attributeerror: 'optionengine' object has no attri

attributeerror: 'optionengine' object has no attribute 'execute

背景

pandas:1.5.2
sqlalchemy:2.0.4


import pandas as pd
from sqlalchemy 
import create_engine # SQLAlchemy v. 2.0!

sql_engine = create_engine('postgresql://user:pass@host:5432/database')

df = pd.read_sql(f'''    SELECT * FROM table LIMIT 100''',
    sql_engine)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

报错


Traceback (most recent call last):
   File "/app/test.py", line 31, in <module>
     df = pd.read_sql(f'''
  File "/usr/local/lib/python3.10/site-packages/pandas/io/sql.py", line 590, in read_sql
     return pandas_sql.read_query(
   File "/usr/local/lib/python3.10/site-packages/pandas/io/sql.py", line 1560, in read_query
     result = self.execute(*args)
   File "/usr/local/lib/python3.10/site-packages/pandas/io/sql.py", line 1405, in execute
     return self.connectable.execution_options().execute(*args, **kwargs)
 AttributeError: 'OptionEngine' object has no attribute 'execute'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

解决

https://github.com/pandas-dev/pandas/issues/40686

在这篇文章中看到,sqlalchemy的1.4和2.0两种不同的语法,pandas暂时还不支持2.0,所以将sqlalchemy回退到1.4.45即可。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/584793
推荐阅读
相关标签
  

闽ICP备14008679号