如何获取导致禁止错误的权限名称?

How to get permission name that causes forbidden error?

我想知道导致禁止错误的权限名称,在禁止视图中获取它并return给用户。怎么做?

金字塔版本 1.10.4

...

# if user does not have PERMISSIONS.name that causes forbidden error
config.add_view(
    SomeView,
    attr="some_class_attribute",
    permission=PERMISSIONS.name,
    renderer="json",
    request_method="GET",
    route_name=route_name,
)

... 

@forbidden_view_config(renderer="json")
def forbidden(request):
    permission_name = get_permission_name(request)
    return permission_name

HTTPForbidden exception has result attr with ACLDenied 类型。 所以permission_name = request.exception.result.permission