python - Bottle 中的基本身份验证和向用户浏览器发送文件
问题描述
我正在尝试在瓶子框架中执行基本身份验证
def is_authenticated_user(user, password):
# This function is called to check if a username/password combination is valid
return username == 'nikos' and password == ******'
并将其称为:
@app.route( '/file', methods=['POST'] )
@auth_basic( is_authenticated_user )
....
....
filename = request.form.get('filename') return static_file( filename, root='/home/nikos/wsgi/static/files' )
我无法完成这项工作,我不明白为什么我得到了不允许的错误方法。static_file 函数也是将文件发送到用户浏览器的正确方法吗?
解决方案
我无法检索作为 request.auth.username 或 request.auth.user 提供给提示的用户名。我怎样才能抓住那个价值?
根据文档,request.auth
是 的元组(user, password)
。像这样检索用户名:
username = request.auth[0]
推荐阅读
- javascript - 通过 eval 访问组件方法中的导入对象
- jmeter - 如何为 JMeter 添加更多间隔响应时间概述
- flutter - 颤动中滚动视图内的Listview
- api - Revit API,访问数据库,试图读取或写入受保护的内存
- amazon-product-api - 阅读亚马逊购物车
- python-3.x - 测试我是否有权在 Python3 的路径中创建文件夹?
- java - 是否可以在 Kotlin 中覆盖静态方法?
- android - 从 Uri android 查找路径
- c# - 如何在运行时在面板上创建按钮的快捷方式?
- jakarta-ee - System.getProperty("user.name") 在服务器和客户端返回相同的结果