Server error on Download PDF

Getting this error when trying to download a PDF of a submitted quotation. I assume it’s a pdf engine problem with wkhtmltopdf. Does wkhtmltopdf need to be installed/repaired? If so, is there documentation on how to do this? Thanks

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 120, in application
    response = frappe.api.handle(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/api/__init__.py", line 52, in handle
    data = endpoint(**arguments)
           ^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/api/v1.py", line 40, in handle_rpc_call
    return frappe.handler.handle()
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/handler.py", line 52, in handle
    data = execute_cmd(cmd)
           ^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/handler.py", line 85, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/__init__.py", line 1754, in call
    return fn(*args, **newargs)
           ^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/utils/typing_validations.py", line 32, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "apps/erpnext/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py", line 514, in get_pdf
    download_pdf(
  File "apps/frappe/frappe/utils/typing_validations.py", line 32, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/utils/print_format.py", line 244, in download_pdf
    pdf_file = frappe.get_print(
               ^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/utils/print_utils.py", line 92, in get_print
    return get_pdf(html, options=pdf_options, output=output)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/utils/pdf.py", line 94, in get_pdf
    filedata = pdfkit.from_string(html, options=options or {}, verbose=True)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "env/lib/python3.11/site-packages/pdfkit/api.py", line 75, in from_string
    return r.to_pdf(output_path)
           ^^^^^^^^^^^^^^^^^^^^^
  File "env/lib/python3.11/site-packages/pdfkit/pdfkit.py", line 201, in to_pdf
    self.handle_error(exit_code, stderr)
  File "env/lib/python3.11/site-packages/pdfkit/pdfkit.py", line 155, in handle_error
    raise IOError('wkhtmltopdf reported an error:\n' + stderr)
OSError: wkhtmltopdf reported an error:
Exit with code 1 due to network error: ConnectionRefusedError

I think you can get this error when you don’t have the site name in your /etc/hosts file on the server.

What type of environment are you in (Docker, Debian, Ubuntu, etc)?

Are you using Multi-tenant/DNS like > bench config dns_multitenant on

Do you have a proxy server in front of your Frappe server?

Ubuntu on Docker, no multitenant and nginx for M365 email.

Exit with code 1 due to network error: ConnectionRefusedError means wkhtmltopdf cannot access the site URL to load print assets (CSS, images).

This usually happens when the site host_name is misconfigured, Nginx is not running, or the port does not match the active web server.

Please verify:

  • wkhtmltopdf 0.12.6 (patched Qt) is installed

  • host_name in site_config points to a reachable URL

  • Nginx is running and accessible from localhost

Once wkhtmltopdf can access /assets/* URLs, PDF generation works correctly.

Try this sollution wkhtmltopdf error everytime i compose · Issue #1680 · frappe/frappe_docker · GitHub

I have been out of the office and will check this momentarily. Thanks

Good morning,

Wanted to follow up with you on this. So, a few days ago I was trying to get https to work which I eventually did. Requiring that I update hostname to my server’s name. Here is that post.

If I change that value back to frontend my https and ngix won’t work. Seems like I’m stuck in a catch 22.

Thoughts?

wkhtmltopdf 0.12.6 (with patched qt)

That is the version installed. I reconfirmed the ngix https is working and my hostname is correct.

I get the same error whether I use the https://myserver (which redirects to http://myserver:8080/ ) or direct to http://myserver:8080/

Stopping nginx has no effect, same error. Accessing site via http gives same error. Seems like something is hardcoded somewhere to look for “frontend” for outputting PDFs?

Other question, does outputting PDF’s use a different port?

If you want to output PDF or use the server name on email links then this is a known problem
Check out Hostname Configuration Issues for Print Formats and Links with docker-compose (pwd.yml) or easy-install.py · Issue #1547 · frappe/frappe_docker · GitHub and see the final workaround works for you

For the sever error i was facing the same form my router one and there is detailed available on the internet.

Sorry I don’t follow?