'OSError' object has no attribute 'message' on PDF Creation

Traceback (most recent call last):
File “/opt/bench/erpnext/apps/frappe/frappe/utils/pdf.py”, line 28, in get_pdf
filedata = pdfkit.from_string(html, False, options=options or {})
File “/opt/bench/erpnext/env/src/pdfkit/pdfkit/api.py”, line 68, in from_string
return r.to_pdf(output_path)
File “/opt/bench/erpnext/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.The switch --disable-smart-shrinking, is not support using unpatched qt, and will be ignored.QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to ‘/tmp/runtime-bench’
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 “/opt/bench/erpnext/apps/frappe/frappe/app.py”, line 60, in application
response = frappe.api.handle()
File “/opt/bench/erpnext/apps/frappe/frappe/api.py”, line 55, in handle
return frappe.handler.handle()
File “/opt/bench/erpnext/apps/frappe/frappe/handler.py”, line 22, in handle
data = execute_cmd(cmd)
File “/opt/bench/erpnext/apps/frappe/frappe/handler.py”, line 61, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File “/opt/bench/erpnext/apps/frappe/frappe/init.py”, line 1038, in call
return fn(*args, **newargs)
File “/opt/bench/erpnext/apps/frappe/frappe/utils/print_format.py”, line 92, in download_pdf
frappe.local.response.filecontent = get_pdf(html)
File “/opt/bench/erpnext/apps/frappe/frappe/utils/pdf.py”, line 35, in get_pdf
if (“ContentNotFoundError” in e.message
AttributeError: ‘OSError’ object has no attribute ‘message’

Whenever trying to generate PDF, getting this error.
Please suggest what to do ?

@nivedita05

Kindly add your “host_name” in your site_config.json

This will definitely work.

I too having this PDF alignment problem. I added host_name but nothing works for me. Any help would be greatly appreciated. Thanks

what will be the host name ? can you give me an example

Keeping this error message in focus, this should help:

@nivedita05

“host_name”:“http://localhost"

Still getting the same error .

Server Error
AttributeError: ‘OSError’ object has no attribute ‘message’

Reinstall WKHTMLTOPDF is works for me…

hi how did you reinstall?

Within the instance i tried to print google search page using wkhtmltopdf package and it works fine . The image was there properly . But inside erpnext it is not working .
Any suggestion?