I have done to implement a print pdf function. I use pyramid, wkhtmltopdf and jinja2 to generate pdf. It works fine in gunicorn. However, when I deploy it to production (I use circusd to run in production), the function fails without any error message. The source code is as follow:
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
So, do you have any suggestion or idea about my problem? It's so straight and I cannot understand why it works fine in gunicorn but fails in circusd
Try setting the
content_length
. It's possible the WSGI server you are using does not support streaming responses (which would happen if you are using.write()
or.app_iter
without setting acontent_length
). For your use-case, it's more likely that you'd be happy just setting thebody
which would take care of everything for you.