我正在尝试使用我编写的以下装饰器对 bottle.py 进行 HTTP 基本身份验证:
def check_auth(username, password):
if username == 'admin' and password == 'pass':
return True
else:
return False
def authenticate(msg_string = "Authenticate."):
response.content_type = "application/json"
message = {'message': msg_string}
resp = jsonpickle.encode(message)
response.status = "401 - Unauthorized"
response.headers['WWW-Authenticate'] = 'Basic realm="PyBit"'
return resp
def requires_auth(f):
def decorated(*args, **kwargs):
print request.auth
auth = request.auth
if not auth:
return authenticate()
elif not check_auth(auth[0],auth[1]):
response.status = "401 - Unauthorized"
return authenticate("HTTP Authentication Failed.")
else:
return f(*args, **kwargs)
return decorated
它可以在内置的 wsgiref 服务器中运行,但当我使用 mod_wsgi 在 Apache 下运行我的应用程序时却不行。在这种情况下,“auth”对象始终为“None”。
阿帕奇在捏它吗?