我正在使用PyCharm CE和Flask在Python中编写RESTful API。我尝试将基本身份验证添加到API。我在应该需要登录的函数之前添加了@ auth.login_required。我添加了一个返回True或False的@ auth.verify_password函数。但是,每次此函数返回True时,它都会显示" TypeError:视图函数未返回有效响应。函数返回None或没有return语句结束。"在Insomnia中执行此操作时,它表示500内部服务器错误。这是我的代码
auth = HTTPBasicAuth()
@auth.verify_password
def verify(username, password):
if not username and password:
return False
if username == "Num of Users":
return False
if username in userData:
return str(userData[username]) == str(password)
return False
以及它吐出的其他信息
127.0.0.1 - - [14/Jun/2018 12:41:49] "DELETE /handshake/delete/1 HTTP/1.1" 500 -
Traceback (most recent call last):
File "/Users/OwenScott/PycharmProjects/RESTful_API_CRD_Backend/venv/lib/python3.6/site-packages/flask/app.py", line 2309, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/OwenScott/PycharmProjects/RESTful_API_CRD_Backend/venv/lib/python3.6/site-packages/flask/app.py", line 2295, in wsgi_app
response = self.handle_exception(e)
File "/Users/OwenScott/PycharmProjects/RESTful_API_CRD_Backend/venv/lib/python3.6/site-packages/flask_restful/__init__.py", line 273, in error_router
return original_handler(e)
File "/Users/OwenScott/PycharmProjects/RESTful_API_CRD_Backend/venv/lib/python3.6/site-packages/flask/app.py", line 1741, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/OwenScott/PycharmProjects/RESTful_API_CRD_Backend/venv/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "/Users/OwenScott/PycharmProjects/RESTful_API_CRD_Backend/venv/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/Users/OwenScott/PycharmProjects/RESTful_API_CRD_Backend/venv/lib/python3.6/site-packages/flask/app.py", line 1816, in full_dispatch_request
return self.finalize_request(rv)
File "/Users/OwenScott/PycharmProjects/RESTful_API_CRD_Backend/venv/lib/python3.6/site-packages/flask/app.py", line 1831, in finalize_request
response = self.make_response(rv)
File "/Users/OwenScott/PycharmProjects/RESTful_API_CRD_Backend/venv/lib/python3.6/site-packages/flask/app.py", line 1957, in make_response
'The view function did not return a valid response. The'