“TypeError:'bool'对象不可调用”

时间:2014-02-10 11:18:19

标签: python json flask

我在GAE上的闪存服务器上出现问题 当我发布一个json对象来注册一个新用户 我收到错误TypeError: 'bool' object is not callable

 ERROR    2014-02-10 11:25:28,787 app.py:1423] Exception on /user [POST]
Traceback (most recent call last):
File "/Users/tomy/Dropbox/RaspberrySpi/RaSPi_Cloud/upbeat-element-358/server/lib/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
  File "/Users/tomy/Dropbox/RaspberrySpi/RaSPi_Cloud/upbeat-element-358/server/lib/flask/app.py", line 1478, in full_dispatch_request
response = self.make_response(rv)
  File "/Users/tomy/Dropbox/RaspberrySpi/RaSPi_Cloud/upbeat-element-358/server/lib/flask/app.py", line 1577, in make_response
rv = self.response_class.force_type(rv, request.environ)
  File "/Users/tomy/Dropbox/RaspberrySpi/RaSPi_Cloud/upbeat-element-358/server/lib/werkzeug/wrappers.py", line 824, in force_type
response = BaseResponse(*_run_wsgi_app(response, environ))
  File "/Users/tomy/Dropbox/RaspberrySpi/RaSPi_Cloud/upbeat-element-358/server/lib/werkzeug/wrappers.py", line 57, in _run_wsgi_app
return _run_wsgi_app(*args)
  File "/Users/tomy/Dropbox/RaspberrySpi/RaSPi_Cloud/upbeat-element-358/server/lib/werkzeug/test.py", line 854, in run_wsgi_app
app_iter = app(environ, start_response)
TypeError: 'bool' object is not callable
INFO     2014-02-10 11:25:28,794 module.py:612] default: "POST /user HTTP/1.1" 500 291

我的代码:

@app.route("/user", methods=["GET", "POST"])
def recieveUser():
    def checkForUser(tempUser):
        query = db.Query(User)
        query.filter('username =', tempUser.username)
        result = query.get()
        if result is None:
            return (False,)
        else:
            return (True,)
    #just in case
    return (False,)
    #end of CheckForUser()

content = request.json
theUser = User(username = content["user_name"],
                    password = content["password"])
if content["method"] == "register":
    if checkForUser(theUser) == (False,):
        theUser.put()
        return json.dumps({"result":"user_added"})
    else:
        return json.dumps({"result":"user_exists"})
elif content["method"] == "login":
    if checkForUser(theUser) == (False,):
        return json.dumps({"result":"no_login"})
    else:
        return json.dumps({"result":"login"})
else:
    return json.dumps({"result":"no_method"})

0 个答案:

没有答案