Search code examples
pythondjangowkhtmltopdf

Django-wkhtmltopdf returned non-zero exit status 1


I'm receiving the following error using wkhtmltopdf in a Django project in development. If I try and run it using an Apache server the status code returned is 6 rather than 1.

Command '['wkhtmltopdf', '--disable-javascript', '--encoding', u'utf8', '--quiet', u'False', '/tmp/wkhtmltopdfnUwu3t.html', '-']' returned non-zero exit status 1

This is my view.

class MyPDF(OrgOwnerMixin, PDFTemplateView):
    filename = 'my_pdf.pdf'
    template_name = 'pdf/test.html'

    def get_object(self, *args, **kwargs):
        return Organisation.objects.get(slug=self.kwargs['slug'])

    def get_context_data(self, *args, **kwargs):
        ctx = super(MyPDF, self).get_context_data(*args, **kwargs)
        ctx['object'] = self.get_object()
        return ctx

And here is the Traceback:

Traceback:

File "/home/henry/Documents/Sites/Development/fargus/env/local/lib/python2.7/site-packages/django/core/handlers/exception.py" in inner
  41.             response = get_response(request)

File "/home/henry/Documents/Sites/Development/fargus/env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
  217.                 response = self.process_exception_by_middleware(e, request)

File "/home/henry/Documents/Sites/Development/fargus/env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
  215.                 response = response.render()

File "/home/henry/Documents/Sites/Development/fargus/env/local/lib/python2.7/site-packages/django/template/response.py" in render
  107.             self.content = self.rendered_content

File "/home/henry/Documents/Sites/Development/fargus/env/local/lib/python2.7/site-packages/wkhtmltopdf/views.py" in rendered_content
  78.             cmd_options=cmd_options

File "/home/henry/Documents/Sites/Development/fargus/env/local/lib/python2.7/site-packages/wkhtmltopdf/utils.py" in render_pdf_from_template
  186.                           cmd_options=cmd_options)

File "/home/henry/Documents/Sites/Development/fargus/env/local/lib/python2.7/site-packages/wkhtmltopdf/utils.py" in convert_to_pdf
  124.     return wkhtmltopdf(pages=filename, **cmd_options)

File "/home/henry/Documents/Sites/Development/fargus/env/local/lib/python2.7/site-packages/wkhtmltopdf/utils.py" in wkhtmltopdf
  110.     return check_output(ck_args, **ck_kwargs)

File "/usr/lib/python2.7/subprocess.py" in check_output
  574.         raise CalledProcessError(retcode, cmd, output=output)

Exception Type: CalledProcessError at /pdf/org-1/
Exception Value: Command '['wkhtmltopdf', '--disable-javascript', '--encoding', u'utf8', '--quiet', u'False', '/tmp/wkhtmltopdfEG5K8j.html', '-']' returned non-zero exit status 1

Any help will be much appreciated


Solution

  • Execute the command wkhtmltopdf --disable-javascript --encoding utf8 --quiet False /tmp/wkhtmltopdfEG5K8j.html -

    And see the error you get.