【问题标题】:Accessing Eve db driver from custom authentication class从自定义身份验证类访问 Eve db 驱动程序
【发布时间】:2017-03-14 13:15:58
【问题描述】:

在我的 setting.py 中,我声明了自定义身份验证类

from flask import current_app as app

class MyAuth(BasicAuth):
    def check_auth(self, username, password, allowed_roles, resource, method):
        users = app.data.driver.db['users']

        ... some logic here...

我在我的一个域中使用它:

my_clients = {
        'schema' :clientsSchema,
        'authentication': MyAuth
}

我收到以下错误:

File " ... eve/settings.py", line 24, in check_auth
users = app.data.driver.db['users']
AttributeError: 'NoneType' object has no attribute 'data'

当 MyAuth 类在 settings.py 中声明时,有什么方法可以从 MyAuth 类访问 Eve db 连接对象并像在 the tutorial 中一样使用它?

【问题讨论】:

  • 您的应用程序运行情况如何?我有一个类似的设置工作。
  • 我用python run.py 运行它,其中run.py 是app = Eve() if __name__ == '__main__': app.run(host='0.0.0.0',port=80)

标签: python rest api authentication eve


【解决方案1】:

你是哪个 Eve 版本的?我认为在旧版本中(在 0.6 之前,访问 db 驱动程序的语法是不同的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-11
    • 1970-01-01
    • 2015-11-21
    • 1970-01-01
    • 2019-05-11
    • 2020-04-01
    • 2022-12-10
    • 1970-01-01
    相关资源
    最近更新 更多