如何在python 2.7中使用flask访问授权头值?

如何在python 2.7中使用flask访问授权头值?,python,flask,basic-authentication,Python,Flask,Basic Authentication,调用端点时,我正在尝试访问授权值。 首先,我添加了以下参数,该参数在Swagger中作为字段显示 parser.add_argument('Authorization', type=str, required=True, help='A base-64 string in format "Basic username:password"', location='headers') 资源的定义如下: from flask import requ

调用端点时,我正在尝试访问授权值。 首先,我添加了以下参数,该参数在Swagger中作为字段显示

parser.add_argument('Authorization', type=str, required=True,
                help='A base-64 string in format "Basic username:password"', location='headers')
资源的定义如下:

from flask import request
parser.add_argument('Authorization', type=str, required=True,
                help='A base-64 string in format "Basic username:password"', location='headers')
@api.route("/authentication/")
@api.expect(parser)
class TestResource(Resource):
    @api.marshal_with(set_test_model)
    def post(self):
        
        val = request.authorization['username']
        if val is None:
            abort(400, 'Username is none')
不幸的是,我得到一个错误,说:

val= request.authorization["username"]
TypeError: 'NoneType' object has no attribute '__getitem__'
通过使用Fiddler观察流量,我发现调用中有一个授权头。 它告诉我:

AUTHORIZATION Header is present: Basic dGVzdDp0ZXN0
Decoded Username:Password= test:test
尽管Fiddler确实识别出了标题,但我似乎无法在python中捕捉到它。
request.header也不包含键“Authorization”。有人知道我是如何使用flask获得授权值的吗?

问题是,我们运行的apache server的旧版本不支持授权安全头。这就是为什么我从未在python中获得任何授权头