'How to get permission name that causes forbidden error?

I want to know permission name that causes forbidden error, get it in forbidden view and return to user. How to do it?

Pyramid version 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


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source