[solved] Wkhtmltopdf HostNotFoundError sending mail after v10 upgrade

Hello, I am getting wkhtmltopdf HostNotFoundError’s when sending documents by email with Send Document Print selected. If I recall correctly, I believe it also happens with a new user “complete registration” email. Has anyone seen this in v10 and has a solution?

I am encountering this on two servers since upgrading erpnext on them to v10 - at least anecdotally. I started with one pre-v10 server and could send a document by email (such as an item master) with “Send Document Print” selected and there was no trouble. Then I upgraded erpnext on the vm to v10 and moved the vm to a new box, which is when I noticed the problem. I subsequently found the original vm also has wkhtmltopdf failures when sending a document by email with “Send Document Print” selected. If “Send Document Print” is not selected, the email is sent (and received) with no trouble.

I would appreciate any suggestions how to troubleshoot this.

wkhtmltopdf reported an error:
Exit with code 1 due to network error: HostNotFoundError

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/email/queue.py", line 418, in send_one
    message = prepare_message(email, recipient.recipient, recipients_list)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/email/queue.py", line 535, in prepare_message
    print_format_file = frappe.attach_print(**attachment)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1266, in attach_print
    "fcontent": get_print(doctype, name, print_format=print_format, style=style, html=html, as_pdf=True, doc=doc)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1249, in get_print
    return get_pdf(html, output = output)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/pdf.py", line 17, in get_pdf
    pdfkit.from_string(html, fname, options=options or {})
  File "/home/frappe/frappe-bench/env/src/pdfkit/pdfkit/api.py", line 68, in from_string
    return r.to_pdf(output_path)
  File "/home/frappe/frappe-bench/env/src/pdfkit/pdfkit/pdfkit.py", line 140, in to_pdf
    raise IOError('wkhtmltopdf reported an error:\n' + stderr.decode('utf-8'))
IOError: wkhtmltopdf reported an error:
Exit with code 1 due to network error: HostNotFoundError

Both servers use the virtual image ("built on October 10, 2017), hosted using VirtualBox. The first vm is NAT’d onto the internet by the VirtualBox router and port 80 is forwarded to port 8080 (to not conflict with an existing web server on the host). The second server is on a host behind a NAT router/firewall. It uses VirtualBox bridged networking, and is configured in the DMZ of the firewall - appearing to the internet as the WAN-side IP address of the router.

Both vm’s were updated to v10 a couple days after it was released, but otherwise the base system has been left as-is.

frappe@erpnext:~/frappe-bench$ bench version
erpnext 10.0.4
frappe 10.0.5
frappe@erpnext:~/frappe-bench$

I’ve been manually sending one of the item documents to an outside email address, and if Send Document Print is selected when the email is sent, the SendGrid control panel shows no email is received. In ERPNext, eventually the activity trail for the item shows that there was an error sending the email and an error log is created (Explore > Setup > Error logs).

Thanks,
Dale

Hi Dale -

pdfkit.py starts up a process that opens a network pipe between client and server.

A few thoughts

  • Can you ssh and scp between the two?
  • For clues check say /var/log/syslog etc in /home/frappe/frappe-bench/logs for error report details
  • identify the ip addresses of your various servers, hosts and VMs, and with telnet or netcat confirm connectivity are as you expect between them

This may offer clues Outgoing Email 'Not Sent'

edit: another PDF Email Problems Thread

Thanks @clarkej for your suggestions. I’ll update after investigating.

This may offer clues https://u5968873.ct.sendgrid.net/wf/click?upn=tpnhN2PDH04qGcoOy06bdSzngX9HFcIvUsr98XA5f6i1l6NOa51mHA-2BGac4bjj6GvrX-2BCKU0RKWE9d4kk5dOSBGT4xkFTdnq5QGIEfnYpgs-3D_ZuKCLNt0LCgufhW9CgVhkSr0OPrjBNrjhMZgUARfiD0tGNFgDDU6cMHkFzUCAPus-2F2NWRaxhktkV87ajFrkXUyWTZ6uR0hYBaCPpmWD4djRojyGtJFuwjZdT0eFSAF-2FoWVmP3jFnzSVFKRJcC6Ba0oM-2BmiDHbiZMVkONV1CeuBdaVfsOuheVaCtH9Y2n56c8FW8sYDHxOmxJ79RrBRMGzg-3D-3D

Coincidentally the same error occurred when I ran this test locally…

frappe@erpnext:~/frappe-bench$ bench run-tests --module 
"frappe.email.doctype.email_account.test_email_account"
   WARNING	Property: Unknown Property name. [11:3: overflow-wrap]
.....E.....

======================================================================
ERROR: test_print_format (frappe.email.doctype.email_account.test_email_account.TestEmailAccount)

Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/doctype/email_account/test_email_account.py”, line 121, in test_print_format
name="_Test Email Account 1", print_format=“Standard”, send_email=True)
File “/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/communication/email.py”, line 85, in make
comm.send(print_html, print_format, attachments, send_me_a_copy=send_me_a_copy)
File “/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/communication/communication.py”, line 189, in send
self.notify(print_html, print_format, attachments, recipients)
File “/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/communication/communication.py”, line 204, in notify
fetched_from_email_account)
File “/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/communication/email.py”, line 130, in notify
recipients=recipients, cc=cc)
File “/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/communication/communication.py”, line 209, in _notify
_notify(self, print_html, print_format, attachments, recipients, cc)
File “/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/communication/email.py”, line 141, in _notify
prepare_to_notify(doc, print_html, print_format, attachments)
File “/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/communication/email.py”, line 251, in prepare_to_notify
print_format=print_format, html=print_html))
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 1262, in attach_print
“fcontent”: get_print(doctype, name, print_format=print_format, style=style, html=html, as_pdf=True, doc=doc)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 1245, in get_print
return get_pdf(html, output = output)
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/pdf.py”, line 17, in get_pdf
pdfkit.from_string(html, fname, options=options or {})
File “/home/frappe/frappe-bench/env/src/pdfkit/pdfkit/api.py”, line 68, in from_string
return r.to_pdf(output_path)
File “/home/frappe/frappe-bench/env/src/pdfkit/pdfkit/pdfkit.py”, line 140, in to_pdf
raise IOError(‘wkhtmltopdf reported an error:\n’ + stderr.decode(‘utf-8’))
IOError: wkhtmltopdf reported an error:
Exit with code 1 due to network error: HostNotFoundError


Ran 11 tests in 11.732s

FAILED (errors=1

But the tests all passed once I added this as recommended:

frappe@erpnext:~/frappe-bench$ find sites -name site_config.json | xargs grep localhost
"host_name": "http://localhost",