无法在circus中响应pdf文件



我已经做了实现打印pdf函数。我使用pyramidwkhtmltopdfjinja2生成pdf。在gunicorn中工作得很好。但是,当我将它部署到生产环境中时(我使用circusd在生产环境中运行),该函数失败了,没有任何错误消息。源代码如下:

pdf_renderer = PDFRenderer()
request = self.request
html = render('test.jinja2' , pdf_data, request)
response = request.response
response.write(pdf_renderer(html))
response.content_type = 'application/pdf'
response.headerlist.append(('Content-Disposition', 'attachment; filename='test.pdf'))
#Everything is ok except the final statement.
#circusd cannot run the statement "return response"
#However, gunicorn can do it
return response
那么,你对我的问题有什么建议或想法吗?它是如此的直,我不明白为什么它在gunicorn中工作得很好,但在circusd

尝试设置content_length。你使用的WSGI服务器可能不支持流响应(如果你使用.write().app_iter而不设置content_length,就会发生这种情况)。对于您的用例,您更有可能乐于设置body,它将为您照顾一切。

response.body = pdf_renderer(html)

最新更新