500内部服务器错误(邮件与Eve集成)

时间:2016-03-23 16:53:38

标签: python mongodb rest postman eve

大家好,我现在正在使用MongoDB& Eve建立一个本地RestAPI连接,它给我一个500内部服务器错误。我正在学习本教程

http://code.tutsplus.com/tutorials/building-rest-apis-using-eve--cms-22961

我目前在“验证用户API”。我按照教程中的确切步骤操作,但是当我尝试获取用户的信息时,它会给我一个“500内部服务器错误”。

https://cms-assets.tutsplus.com/uploads/users/442/posts/22961/image/val87878.png

这是我收到错误的地方。因此,不会出现用户信息,而是出现500内部服务器错误。为什么会这样?以下是我的代码。

Settings.py

from Authenticate import Authenticate

RESOURCE_METHODS = ['GET', 'POST']

DOMAIN = {
    'user': {
        'additional_lookup': {
                'url': 'regex("[\w]+")',
                'field': 'username',
            },
        'schema': {
            'firstname': {
                'type': 'string'
            },
            'lastname': {
                'type': 'string'
            },
            'username': {
                'type': 'string',
                 'unique': True
            },
            'password': {
                'type': 'string'
            },
            'phone': {
                'type': 'string'
            },
        }
    }


}

api.py

from eve import Eve
from Authenticate import Authenticate

if __name__ == '__main__':
    app = Eve(auth=Authenticate)
    app.run()

Authenticate.py

from eve.auth import BasicAuth

class Authenticate(BasicAuth):
    def check_auth(self, username, password, allowed_roles, resource,
                   method):
        if resource == 'user' and method == 'GET':
            user = app.data.driver.db['user']
            user = user.find_one({'username': username,'password':password})
            if user:
                return True
            else:
                return False
        elif resource == 'user' and method == 'POST':
            return username == 'admin' and password == 'admin'
        else:
            return True

0 个答案:

没有答案