【问题标题】:Cannot response a pdf file in circus无法响应马戏团中的 pdf 文件
【发布时间】:2013-04-27 12:21:55
【问题描述】:

我已经实现了打印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 中却失败了

【问题讨论】:

  • circusd 你的意思是 chaussette,如果是,什么后端? Circus 不是 WSGI 服务器,应该不会影响可以发送的响应类型。

标签: pyramid wkhtmltopdf circusd


【解决方案1】:

尝试设置content_length。您使用的 WSGI 服务器可能不支持流式响应(如果您使用 .write().app_iter 而不设置 content_length,则会发生这种情况)。对于您的用例,您更有可能只设置 body 会为您处理所有事情。

response.body = pdf_renderer(html)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-19
    • 2017-04-17
    • 2018-12-03
    • 1970-01-01
    • 1970-01-01
    • 2014-12-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多