AttributeError:“ NoneType”对象没有属性“ _instantiate_plugins”(无法导入create_engine) [英] AttributeError: 'NoneType' object has no attribute '_instantiate_plugins' (Cannot import create_engine)
问题描述
import os
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
engine=create_engine(os.getenv("DATABASE_URL"))
db = scoped_session(sessionmaker(bind=engine))
def main():
flights = db.execute("SELECT origin, destination, duration FROM flights").fetchall()
for flight in flights:
print(f"{flight.origin} to {flight.destination}, {flight.duration} minutes.")
if __name__ == "__main__":
main()
回溯(最近一次通话最近):
文件 list.py,第6行,在
engine = create_engine(os.getenv( DATABASE_URL))中
文件 C: \用户\Aakash\AppData\本地\程序\Python\Python38-32\lib\站点包\sqlalchemy\engine__init __。py,
行479,在create_engine中
return strategy.create(* args,** kwargs)
文件 C:\Users\Aakash\AppData\Local\Programs\Python\Python38-32\lib \site-pa ckages\sqlalchemy\engine\strategies.py,第56行,在创建
插件= u._instantiate_plugins(kwargs)
AttributeError:'NoneType'对象没有属性'_instantiate_plugins'
Traceback (most recent call last): File "list.py", line 6, in engine=create_engine(os.getenv("DATABASE_URL")) File "C:\Users\Aakash\AppData\Local\Programs\Python\Python38-32\lib\site-packages\sqlalchemy\engine__init__.py", line 479, in create_engine return strategy.create(*args, **kwargs) File "C:\Users\Aakash\AppData\Local\Programs\Python\Python38-32\lib\site-packages\sqlalchemy\engine\strategies.py", line 56, in create plugins = u._instantiate_plugins(kwargs) AttributeError: 'NoneType' object has no attribute '_instantiate_plugins'
如果将我的代码更改为:
And if change my code to:
推荐答案
只需将其用作url
postgresql:// username:password @ host:port / database
直接将这些值传递到您的 create_engine( postgresql:// username: password @ host:port / database)
just use this as url
"postgresql://username:password@host:port/database"
directly pass these values inside your create_engine("postgresql://username:password@host:port/database")
我现在遇到了同样的问题。这对我有用。值得一提的是,在创建新用户和数据库并移动表之后,我完全得到了一个不同的错误。错误是'
I was having the same problem now its gone.That worked for me. Only thing important to mention is that I got a different error altogether after creating the new user and database and moving the tables. The error was '
''ModuleNotFoundError:没有名为'psycopg2'的模块'''
'' ModuleNotFoundError: No module named 'psycopg2' '''
并且该解决方案正在运行: pip3安装psycopg2-binary
and the solution was running: pip3 install psycopg2-binary
PS:URL详细信息以及您的详细信息。
PS: URL details with you details.
这篇关于AttributeError:“ NoneType”对象没有属性“ _instantiate_plugins”(无法导入create_engine)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!