捕获异常但浏览器仍显示错误页面

时间:2017-11-15 12:52:20

标签: aiohttp

我有一个或多或少的处理程序:

async def handler(request):
    response = web.StreamResponse(headers={
    'Content-Type': 'text/plain; charset=utf-8',
    'Connection': 'keep-alive',
    })
    response.enable_chunked_encoding()
    await stream_response.prepare(request)
    try:
        await do_a_thing(response) # writes into response
    except Exception as e:
        # log the exception. I sometimes catch a CancelledError here
    await response.write_eof()
    return response

当没有出错时,页面生成正常。 当do_a_thing()中出现CancelledError时,浏览器会显示错误页面ERR_INCOMPLETE_CHUNKED_ENCODING,即使:

  • 在写入响应时肯定没有发生CancelledError(它在HTTP GET期间发送到do_a_thing()中的另一个URL)
  • 我抓住了异常
  • 我没有做任何不同的事情来写EOF并返回回复

我必须做错事,或做错事,但我无法说清楚。

任何人都可以看到它可能是什么吗?

0 个答案:

没有答案