当前位置: 首页>>代码示例>>Python>>正文


Python Response.headers['x-amzn-RequestId']方法代码示例

本文整理汇总了Python中pyramid.response.Response.headers['x-amzn-RequestId']方法的典型用法代码示例。如果您正苦于以下问题:Python Response.headers['x-amzn-RequestId']方法的具体用法?Python Response.headers['x-amzn-RequestId']怎么用?Python Response.headers['x-amzn-RequestId']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyramid.response.Response的用法示例。


在下文中一共展示了Response.headers['x-amzn-RequestId']方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: pyramid_router

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import headers['x-amzn-RequestId'] [as 别名]
def pyramid_router(request):
    # extract action
    target = request.headers.get('x-amz-target')
    action = target.split('.', 2)[1] if target is not None else ""

    post = request.json

    # do the job
    try:
        auth = request.headers["Authorization"]
        if not auth.startswith("AWS4-HMAC-SHA256"):
            raise MissingAuthenticationTokenException
        auth = auth[len("AWS4-HMAC-SHA256 "):]
        auth = auth.split(", ")
        auth = dict([x.split("=",2) for x in auth])
        access_key = auth["Credential"].split("/")[0]
        if access_key not in config.keys():
            req_logger.error("Access denied for %s", access_key)
            raise AccessDeniedException, "Can't find %s in users" % access_key
        user = config_for_user(access_key)
        sleep(user["DELAY_OPERATIONS"])
        fail_every = user["FAIL_EVERY_N"]
        if fail_every != None:
            if fail_every + 1 == user[FAIL_KEY]: # hit the fail time
                reset_fail(access_key)
                raise InternalServerError("The server encountered an internal error trying to fulfill the request")

        body = router(action, post, user)
        status = '200 OK'
    except DDBError as e:
        body = e.to_dict()
        status = '{} {}'.format(e.status, e.status_str)
        user = None

    # prepare output
    response = Response()
    response.body = json.dumps(body)
    response.status = status
    response.content_type = 'application/x-amz-json-1.0'
    if post.has_key("request_id"): # might not be present if user auth failed
        response.headers['x-amzn-RequestId'] = post['request_id']  # added by router

    # done
    return response
开发者ID:lshift,项目名称:ddbmock,代码行数:46,代码来源:pyramid.py

示例2: pyramid_router

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import headers['x-amzn-RequestId'] [as 别名]
def pyramid_router(request):
    # extract action
    target = request.headers.get('x-amz-target')
    action = target.split('.', 2)[1] if target is not None else ""

    post = request.json

    # do the job
    try:
        body = router(action, post)
        status = '200 OK'
    except DDBError as e:
        body = e.to_dict()
        status = '{} {}'.format(e.status, e.status_str)

    # prepare output
    response = Response()
    response.body = json.dumps(body)
    response.status = status
    response.content_type = 'application/x-amz-json-1.0'
    response.headers['x-amzn-RequestId'] = post['request_id']  # added by router

    # done
    return response
开发者ID:dekked,项目名称:dynamodb-mock,代码行数:26,代码来源:pyramid.py


注:本文中的pyramid.response.Response.headers['x-amzn-RequestId']方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。