【发布时间】:2020-11-29 07:30:33
【问题描述】:
我在 Flask 上使用 HTTP Digest 身份验证的基本代码,但它对我不起作用。 我总是收到错误代码 401。我正在使用 Postman 应用程序发送 HTTP 请求。
我的代码: 从烧瓶进口烧瓶 从 flask_httpauth 导入 HTTPDigestAuth
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret key here'
auth = HTTPDigestAuth()
users = {
"john": "hello",
"Admin": "Admin",
"susan": "bye"
}
@auth.get_password
def get_pw(username):
if username in users:
return users.get(username)
return None
@app.route('/', methods=['GET', 'POST'])
@auth.login_required
def index():
return "Hello, {}!".format(auth.username())
if __name__ == '__main__':
app.run()
以下是运行结果:
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [29/Nov/2020 09:22:32] "POST / HTTP/1.1" 401 -
127.0.0.1 - - [29/Nov/2020 09:22:32] "POST / HTTP/1.1" 401 -
【问题讨论】:
标签: python flask digest-authentication