gpt4 book ai didi

python - 无法加载插件 : sqlalchemy. 方言:sqlite3

转载 作者:太空狗 更新时间:2023-10-30 00:34:34 25 4
gpt4 key购买 nike

我正在学习使用 Python 创建 API here .我已经准备好一切并下载了数据库,但是当我运行我的应用程序时出现以下错误:

Traceback (most recent call last):
File "app.py", line 7, in <module>
e = create_engine("sqlite3:///salaries.db")
File "C:\Python27\lib\site-packages\sqlalchemy\engine\__init__.py", line 387, in create_engine
return strategy.create(*args, **kwargs)
File "C:\Python27\lib\site-packages\sqlalchemy\engine\strategies.py", line 56, in create
entrypoint = u._get_entrypoint()
File "C:\Python27\lib\site-packages\sqlalchemy\engine\url.py", line 139, in _get_entrypoint
cls = registry.load(name)
File "C:\Python27\lib\site-packages\sqlalchemy\util\langhelpers.py", line 212, in load
(self.group, name))
sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:sqlite3

我在哪里做错了它不会加载正确的插件?

from flask import Flask, request
from flask_restful import Resource, Api
from sqlalchemy import create_engine
from json import dumps


e = create_engine("sqlite3:///salaries.db")

app = Flask(__name__)
api = Api(app)


class DepartmentsMeta(Resource):
def get(self):
conn = e.connect()
query = conn.execute("select distinct DEPARTMENT from salaries")
return {"departments": [i[0] for i in query.cursor.fetchall()]}


class DepartmentSalary(Resource):
def get(self, department_name):
conn = e.connect()
query = conn.execute("select * from salaries where Department='%s'" % department_name)
result = {"data": [dict(zip(tuple(query.keys()), i))] for i in query.cursor}
return result


api.add_resource(DepartmentSalary, "/dept/<string:department_name>")
api.add_resource(DepartmentsMeta, "/department")


if __name__ == "__main__":
app.run()

最佳答案

请尝试替换这一行:

e = create_engine("sqlite3:///salaries.db")

e = create_engine("sqlite:///salaries.db")

关于python - 无法加载插件 : sqlalchemy. 方言:sqlite3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42032382/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com