# Buggy code
def view_lookup(request, uri):
    """
    Look-up the specified `uri` and return the associated resource name
    along the match dict.

    :param request: the current request (used to obtain registry).
    :param uri: a plural or object endpoint URI.
    :rtype: tuple
    :returns: the resource name and the associated matchdict.
    """
    api_prefix = "/%s" % request.upath_info.split("/")[1]
    # Path should be bytes in PY2, and unicode in PY3
    path = _encoded(api_prefix + uri)

    q = request.registry.queryUtility
    routes_mapper = q(IRoutesMapper)

    fakerequest = Request.blank(path=path)
    info = routes_mapper(fakerequest)
    matchdict, route = info["match"], info["route"]
    resource_name = route.name.replace("-record", "").replace("-collection", "")
    return resource_name, matchdict


# Traceback (AttributeError)
ERROR  "GET   /v1/permissions" ? (? ms) 'NoneType' object has no attribute 'name' agent=node-fetch/1.0 (+https://github.com/bitinn/node-fetch) authn_type=basicauth errno=None exception=Traceback (most recent call last):
File "/home/mathieu/Code/Mozilla/kinto-client/.venv/local/lib/python2.7/site-packages/pyramid/tweens.py", line 22, in excview_tween
response = handler(request)
File "/home/mathieu/Code/Mozilla/kinto-client/.venv/local/lib/python2.7/site-packages/pyramid_tm/__init__.py", line 101, in tm_tween
reraise(*exc_info)
File "/home/mathieu/Code/Mozilla/kinto-client/.venv/local/lib/python2.7/site-packages/pyramid_tm/__init__.py", line 83, in tm_tween
response = handler(request)
File "/home/mathieu/Code/Mozilla/kinto-client/.venv/local/lib/python2.7/site-packages/pyramid/router.py", line 158, in handle_request
view_name
File "/home/mathieu/Code/Mozilla/kinto-client/.venv/local/lib/python2.7/site-packages/pyramid/view.py", line 547, in _call_view
response = view_callable(context, request)
File "/home/mathieu/Code/Mozilla/kinto-client/.venv/local/lib/python2.7/site-packages/pyramid/config/views.py", line 182, in __call__
return view(context, request)
File "/home/mathieu/Code/Mozilla/kinto-client/.venv/local/lib/python2.7/site-packages/pyramid/viewderivers.py", line 393, in attr_view
return view(context, request)
File "/home/mathieu/Code/Mozilla/kinto-client/.venv/local/lib/python2.7/site-packages/pyramid/viewderivers.py", line 371, in predicate_wrapper
return view(context, request)
File "/home/mathieu/Code/Mozilla/kinto-client/.venv/local/lib/python2.7/site-packages/pyramid/viewderivers.py", line 442, in rendered_view
result = view(context, request)
File "/home/mathieu/Code/Mozilla/kinto-client/.venv/local/lib/python2.7/site-packages/pyramid/viewderivers.py", line 147, in _requestonly_view
response = view(request)
File "/home/mathieu/Code/Mozilla/kinto-client/.venv/local/lib/python2.7/site-packages/cornice/service.py", line 573, in wrapper
response = view_(request)
File "/home/mathieu/Code/Mozilla/kinto/kinto/views/permissions.py", line 41, in permissions_get
resource_name, matchdict = core_utils.view_lookup(request, object_uri)
File "/home/mathieu/Code/Mozilla/kinto/kinto/core/utils.py", line 390, in view_lookup
resource_name = route.name.replace('-record', '')\
AttributeError: 'NoneType' object has no attribute 'name' lang=None uid=a9d81e1b56f2b77103e87601621a99b3d82a15abf7c72ce57a032d0964317c7a

# Fixed code
def view_lookup(request, uri):
    """
    Look-up the specified `uri` and return the associated resource name
    along the match dict.

    :param request: the current request (used to obtain registry).
    :param uri: a plural or object endpoint URI.
    :rtype: tuple
    :returns: the resource name and the associated matchdict.
    """
    api_prefix = "/%s" % request.upath_info.split("/")[1]
    # Path should be bytes in PY2, and unicode in PY3
    path = _encoded(api_prefix + uri)

    q = request.registry.queryUtility
    routes_mapper = q(IRoutesMapper)

    fakerequest = Request.blank(path=path)
    info = routes_mapper(fakerequest)
    matchdict, route = info["match"], info["route"]
    if route is None:
        raise ValueError("URI has no route")

    resource_name = route.name.replace("-record", "").replace("-collection", "")
    return resource_name, matchdict