Wkhtmltopdf [Errno 2] - frappe.email.queue.flush

Hi,

I’m facing this error:

'OSError' object has no attribute 'message'
Traceback (most recent call last):
  File "/home/frappe/frappe-bench/env/src/pdfkit/pdfkit/configuration.py", line 21, in __init__
    with open(self.wkhtmltopdf) as f:
FileNotFoundError: [Errno 2] No such file or directory: b''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/pdf.py", line 25, in get_pdf
    filedata = pdfkit.from_string(html, False, options=options or {})
  File "/home/frappe/frappe-bench/env/src/pdfkit/pdfkit/api.py", line 66, in from_string
    configuration=configuration)
  File "/home/frappe/frappe-bench/env/src/pdfkit/pdfkit/pdfkit.py", line 38, in __init__
    self.configuration = (Configuration() if configuration is None
  File "/home/frappe/frappe-bench/env/src/pdfkit/pdfkit/configuration.py", line 27, in __init__
    'https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf' % self.wkhtmltopdf)
OSError: No wkhtmltopdf executable found: "b''"
If this file exists please check that this process can read it. Otherwise please install wkhtmltopdf - https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/email/queue.py", line 439, in send_one
    message = prepare_message(email, recipient.recipient, recipients_list)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/email/queue.py", line 571, in prepare_message
    print_format_file = frappe.attach_print(**attachment)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1391, in attach_print
    "fcontent": get_print(doctype, name, print_format=print_format, style=style, html=html, as_pdf=True, doc=doc, no_letterhead=no_letterhead, password=password)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1368, in get_print
    return get_pdf(html, output = output, options = options)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/pdf.py", line 32, in get_pdf
    if ("ContentNotFoundError" in e.message
AttributeError: 'OSError' object has no attribute 'message'

Somebody have a tip about it?

Thanks!

See this post

Hi trentmu,

I did it. Has already read this. Got the same error:

Erro
'OSError' object has no attribute 'message'
Traceback (most recent call last):
  File "/home/frappe/frappe-bench/env/src/pdfkit/pdfkit/configuration.py", line 21, in __init__
    with open(self.wkhtmltopdf) as f:
**FileNotFoundError: [Errno 2] No such file or directory: b''**

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/pdf.py", line 25, in get_pdf
    filedata = pdfkit.from_string(html, False, options=options or {})
  File "/home/frappe/frappe-bench/env/src/pdfkit/pdfkit/api.py", line 66, in from_string
    configuration=configuration)
  File "/home/frappe/frappe-bench/env/src/pdfkit/pdfkit/pdfkit.py", line 38, in __init__
    self.configuration = (Configuration() if configuration is None
  File "/home/frappe/frappe-bench/env/src/pdfkit/pdfkit/configuration.py", line 27, in __init__
    'https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf' % self.wkhtmltopdf)
OSError: **No wkhtmltopdf executable found: "b''"**

** If this file exists please check that this process can read it. Otherwise please install wkhtmltopdf - Installing wkhtmltopdf · JazzCore/python-pdfkit Wiki · GitHub**

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/email/queue.py", line 404, in send_one
    message = prepare_message(email, recipient.recipient, recipients_list)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/email/queue.py", line 536, in prepare_message
    print_format_file = frappe.attach_print(**attachment)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1391, in attach_print
    "fcontent": get_print(doctype, name, print_format=print_format, style=style, html=html, as_pdf=True, doc=doc, no_letterhead=no_letterhead, password=password)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1368, in get_print
    return get_pdf(html, output = output, options = options)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/pdf.py", line 32, in get_pdf
    if ("ContentNotFoundError" in e.message
**AttributeError: 'OSError' object has no attribute 'message'**

Seams to be something related to wkhtmltopdf… And I saw something on the v12.0.8 release related to it

fix(travis): Install wkhtmltopdf

I did the update, and nothing happened…

Any kind light here?

Do you have wkhtmltopdf installed?
Try executing:

wkhtmltopdf --version

Try this command:

sudo apt-get update
sudo apt install wkhtmltopdf
sudo wget https://builds.wkhtmltopdf.org/0.12.1.3/wkhtmltox_0.12.1.3-1~bionic_amd64.deb
sudo cp /var/backups/dpkg.status.0 /var/lib/dpkg/status
sudo apt-get update
sudo dpkg -i wkhtmltox_0.12.1.3-1~bionic_amd64.deb
sudo apt-get install -f
sudo ln -s /usr/local/bin/wkhtmltopdf /usr/bin
sudo ln -s /usr/local/bin/wkhtmltoimage /usr/bin

I normally install later version of wkhtmltopdf using these commands…

#wkhtmltopdf - the default apt-get version is outdated. Install pre-reqs, and then a manual/latest version
sudo apt install -y xfonts-75dpi fontconfig libxrender1 xfonts-base
wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.stretch_amd64.deb
sudo dpkg --install wkhtmltox_0.12.5-1.stretch_amd64.deb

Hi!

Thanks for your help:

wkhtmltopdf 0.12.3 (with patched qt)

Now, with your help, and this https://discuss.frappe.io/t/v11-pdf-file-dont-apply-css-and-image/41793/42:

wkhtmltopdf 0.12.5 (with patched qt)

And now the error has changed:

'OSError' object has no attribute 'message'
Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/pdf.py", line 25, in get_pdf
    filedata = pdfkit.from_string(html, False, 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 143, in to_pdf
    raise IOError("wkhtmltopdf exited with non-zero code {0}. error:\n{1}".format(exit_code, stderr.decode("utf-8")))
OSError: wkhtmltopdf exited with non-zero code 1. error:
The switch --print-media-type, is not support using unpatched qt, and will be ignored.The switch --header-html, is not support using unpatched qt, and will be ignored.The switch --footer-html, is not support using unpatched qt, and will be ignored.QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-frappe'
qt.qpa.screen: QXcbConnection: Could not connect to display 
Could not connect to any X display.


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/email/queue.py", line 404, in send_one
    message = prepare_message(email, recipient.recipient, recipients_list)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/email/queue.py", line 536, in prepare_message
    print_format_file = frappe.attach_print(**attachment)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1391, in attach_print
    "fcontent": get_print(doctype, name, print_format=print_format, style=style, html=html, as_pdf=True, doc=doc, no_letterhead=no_letterhead, password=password)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1368, in get_print
    return get_pdf(html, output = output, options = options)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/pdf.py", line 32, in get_pdf
    if ("ContentNotFoundError" in e.message
AttributeError: 'OSError' object has no attribute 'message'

Still searching… Thanks for all your help… I’ll try to resend the message… let’s see…

The problem here is your local can’t display the PDF being forwarded to it from the remote. To connect two X window environments try this

ssh -X frappe@yourremoteip

reference How do I fix a "cannot open display" error when opening an X program after ssh'ing with X11 forwarding enabled? - Super User