Flask werkzeug request.authorization is none but Authorization headers present

后端 未结 3 2166
甜味超标
甜味超标 2020-12-16 15:48

I am POSTing some JSON data and adding an Authorization header. However, the request object does not have the correct authorization property. HTTP_AUTHORI

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-16 16:35

    Your authorization header ('Authorization', 'testkey:') needs to be Base64 encoded and include Basic.

    in python:

    import base64
    base64.b64encode('testkey:') # 'dGVzdGtleTo='
    

    in javascript set your header using btoa:

    '{"Authorization": "Basic ' + btoa('testkey:') + '"}' 
    '{"Authorization": "Basic dGVzdGtleTo="}' 
    

    In your case, the this will result in the header coming in as:

    ('Authorization', 'Basic dGVzdGtleTo=')

提交回复
热议问题