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

标签 python python-2.7 sqlalchemy

我正在学习使用 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/

相关文章:

python - 尝试使用 python 从 azure 函数触发 url,错误提示 "without a $return binding returned a non-None value"

python - 如何强制日期时间在 python 中保留 0 微秒

python - Pylons 1.0 和 SQLAlchemy 0.6 - 如何建模?

python - "D"消息中的数据不足

python - 如何设置条件不存在的查询?

python - Modbus 错误 : [Input/Output] No Response received from the remote unit

python - 无法通过Python访问Samba服务器上的文件

python - 使自定义记录器可跨多个模块使用

python - 什么时候使用迭代器,什么时候使用生成器?

python-2.7 - DistributionNotFound 在 Mac OS X 上运行 flake8