Wklhtmltopdf Exit with code 1 due to network error: HostNotFoundError

Hey there

I get the following error when trying to generate a pdf:

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 53, in handle
    data = execute_cmd(cmd)
           ^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/handler.py", line 86, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/__init__.py", line 1760, in call
    return fn(*args, **newargs)
           ^^^^^^^^^^^^^^^^^^^^
  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 246, 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: HostNotFoundError

The one other thread on this topic didn’t seem to have found a solution for this, and it was for docker installation, so i’m not sure whether that solution applies to my scenario as mine as is not a docker installation. Anyone able to point me in the right direction to solve this?

That’s a networking problem, probably related to DNS. The wkhtmltopdf binary needs to be able to resolve the frappe site.

Try the bench set-url-root command if it’s all on one machine:

https://frappeframework.com/docs/user/en/bench/bench-commands


> bench set-url-root --help
Usage: bench set-url-root [OPTIONS] SITE URL_ROOT

  Set URL root for site

Options:
  --help  Show this message and exit.

Example: bench set-url-root site1.local https://mysite.domain.com

Also, Frappe Commands

bench add-to-hosts

might help.