需要在标题restPlus中传递apikey、用户名、客户id

2024-10-06 12:30:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试在标题中传递apikey、username、customer\u id,这里可以通过另一种格式进行apikey授权,但无法在标题中传递username、customer\u id

@api.header('X-Consumer-Custom-ID')
@api.header('X-Consumer-Username')
class check(Resource):
@login_required
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('id', type=str, location='form', required=True)
        parser.add_argument('X-Consumer-Custom-ID', location='headers')
        parser.add_argument('X-Consumer-Username', location='headers')
        args = parser.parse_args()
        order_id = args['id']

标题中另一种格式的apiKey授权:

authorizations = {
    'apikey': {
        'type': 'apiKey',
        'in': 'header',
        'name': 'X-API-KEY'
    }}
app = Flask(__name__)
SWAGGER_DOC = True
api = Api(app, authorizations=authorizations, security=['apikey'], version='dev',
          title='Awesome Flask APIs',
          doc="/" if SWAGGER_DOC is True else False,
          description='Awesome RESTful APIs, written in Flask', )

请帮助我,我想通过三个参数,任何想法或建议将不胜感激


Tags: addapiidtrueparser标题flaskconsumer