1

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

Thinh Phan
  • 655
  • 1
  • 14
  • 27
  • By `circusd` do you mean chaussette, and if so, what backend? Circus is not a WSGI server and should have no effect on the types of responses that can be sent. – Michael Merickel May 03 '13 at 08:20

1 Answers1

1

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 a content_length). For your use-case, it's more likely that you'd be happy just setting the body which would take care of everything for you.

response.body = pdf_renderer(html)
Michael Merickel
  • 23,153
  • 3
  • 54
  • 70