gpt4 book ai didi

python - 无法从 Python EVE API 返回数据

转载 作者:太空宇宙 更新时间:2023-11-04 05:56:11 24 4
gpt4 key购买 nike

这是我的 Python EVE 代码

from eve import Eve
from eve.auth import BasicAuth

class MyBasicAuth(BasicAuth):
def check_auth(self, username, password, allowed_roles, resource,
method):
if resource == 'auth':
user = app.data.driver.db['user']
user = user.find_one({'email': username,'password':password})
if user:
return user
else:
False
else:
return True

app = Eve(auth=MyBasicAuth)

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

验证成功后,我将返回 user 对象,但未返回任何内容。我哪里错了。这是settings.py文件

RESOURCE_METHODS = ['GET', 'POST']

DOMAIN = {
'user': {
'schema': {
'firstname': {
'type': 'string'
},
'lastname': {
'type': 'string'
},
'email': {
'type': 'string'
},
'password': {
'type': 'string'
},
'phone': {
'type': 'string'
}
}
},
'auth': {
'schema': {
'username': {
'type': 'string'
},
'password': {
'type':'string'
}
}
}
}

最佳答案

身份验证和授权与返回数据无关。您的 MyBasicAuth 类只应返回 TrueFalse 以允许处理或拒绝当前请求。

假设您的客户端正在访问 user 端点,如果出现以下情况,它将返回数据:

  1. 您的自定义身份验证类返回 True

  2. 数据库中的 user 集合中有文档(您没有提供 datasource,因此 Eve 默认将端点作为数据源名称)。

此外,我不确定您为什么要测试 resource == 'auth',因为您没有在您的域中设置 auth 端点。

为了抢先一步,您可能需要检查 QuickStart首先,然后 Authentication and Authorization最后是 RESTful Account Management教程。

关于python - 无法从 Python EVE API 返回数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27674715/

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