Here are the examples of the python api aiohttp.web.HTTPNotAcceptable taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
2 Examples
3
Example 1
def select_renderer(request: web.Request, renderers: OrderedDict, force=True):
"""
Given a request, a list of renderers, and the ``force`` configuration
option, return a two-tuple of:
(media type, render callable). Uses mimeparse to find the best media
type match from the ACCEPT header.
"""
header = request.headers.get('ACCEPT', '*/*')
best_match = mimeparse.best_match(renderers.keys(), header)
if not best_match or best_match not in renderers:
if force:
return tuple(renderers.items())[0]
else:
raise web.HTTPNotAcceptable
return best_match, renderers[best_match]
3
Example 2
def render_mako(request, data):
handler = request.match_info.handler
template_name = handler.__dict__.get('template', None)
if not template_name:
raise web.HTTPNotAcceptable(text='text/html not supported.')
if not isinstance(data, Mapping):
raise web.HTTPInternalServerError(
text="context should be mapping, not {}".format(type(data)))
template = request.app['mako_lookup'].get_template(template_name)
text = template.render_unicode(**data)
return web.Response(text=text, content_type=request['selected_media_type'])