Download PDF Error

Hi,

Can any one help me to solve this problem, One we click on DOWNLOAD PDF we are getting below server error

Traceback (innermost last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/app.py”, line 52, in application
response = frappe.api.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/api.py”, line 42, in handle
return frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 66, in handle
execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 89, in execute_cmd
ret = frappe.call(method, **frappe.form_dict)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 531, in call
return fn(*args, **newargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/templates/pages/print.py”, line 94, in download_pdf
frappe.local.response.filecontent = get_pdf(html)
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/pdf.py”, line 28, in get_pdf
pdfkit.from_string(html, fname, options=options or {})
File “/home/frappe/frappe-bench/env/lib/python2.7/site-packages/pdfkit/api.py”, line 66, in from_string
configuration=configuration)
File “/home/frappe/frappe-bench/env/lib/python2.7/site-packages/pdfkit/pdfkit.py”, line 38, in init
self.configuration = (Configuration() if configuration is None
File “/home/frappe/frappe-bench/env/lib/python2.7/site-packages/pdfkit/configuration.py”, line 27, in init
https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf’ % self.wkhtmltopdf)
IOError: No wkhtmltopdf executable found: “”
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

I did update the Bench update, But still error is same.

Regards
Waheed

Have you installed wkhtmltopdf?

Yes it was successfully installed during Setup, Below is the Screen Shoot

Just in case the install script lies ;-), try testing wkhtmltopdf by itself.

# wkhtmltopdf http://erpnext.com erpnext.pdf

and open erpnext.pdf in a pdf viewer.

Its look like wkhtmltopdf is installed and working, but problem only in erpnext we are not able to get download PDF

Try after running
ln -s /usr/local/bin/wkhtmltopdf /usr/bin/wkhtmltopdf

After doing above command this error is coming now . Still there some problem

Traceback (innermost last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/app.py”, line 52, in application
response = frappe.api.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/api.py”, line 42, in handle
return frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 66, in handle
execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 89, in execute_cmd
ret = frappe.call(method, **frappe.form_dict)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 531, in call
return fn(*args, **newargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/templates/pages/print.py”, line 94, in download_pdf
frappe.local.response.filecontent = get_pdf(html)
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/pdf.py”, line 28, in get_pdf
pdfkit.from_string(html, fname, options=options or {})
File “/home/frappe/frappe-bench/env/lib/python2.7/site-packages/pdfkit/api.py”, line 68, in from_string
return r.to_pdf(output_path)
File “/home/frappe/frappe-bench/env/lib/python2.7/site-packages/pdfkit/pdfkit.py”, line 116, in to_pdf
raise IOError(‘wkhtmltopdf reported an error:\n’ + stderr.decode(‘utf-8’))
IOError: wkhtmltopdf reported an error:
Loading pages (1/6)
[> ] 0%
[======> ] 10%
[==========> ] 17%
Warning: Failed to load file:///tmp/localhost/assets/frappe/css/bootstrap.css (ignore)
Warning: Failed to load file:///tmp/localhost/files/Fast Link (2)400(1).jpg (ignore)
[============================================================] 100%
Counting pages (2/6)
[============================================================] Object 1 of 1
Warning: Received createRequest signal on a disposed ResourceObject’s NetworkAccessManager. This migth be an indication of an iframe taking to long to load.
Warning: Received createRequest signal on a disposed ResourceObject’s NetworkAccessManager. This migth be an indication of an iframe taking to long to load.
Resolving links (4/6)
[============================================================] Object 1 of 1
Loading headers and footers (5/6)
Printing pages (6/6)
[> ] Preparing
[==============================> ] Page 1 of 2
[============================================================] Page 2 of 2
Done
Exit with code 1 due to network error: ContentNotFoundError

There is anything els we have to do for download PDF

Can you try after,

bench update # updates bench tool and erpnext to latest version
bench setup nginx # regenerates nginx config

# as root run,
service nginx restart
1 Like

This is what is coming now on Web access, Now i am not able to access the erpnext…

Updating. We will be back in a few moments…

Help me to solve this problem

was there an exception when updating ?
Run bench update again if you missed it.

I did bench update

[root@erpserver frappe-bench]# bench update
Already up-to-date.
From https://github.com/frappe/erpnext

Running latest for site1.local

Executing erpnext.patches.v4_2.discount_amount in site1.local (site1.local)
Traceback (most recent call last):
File “/home/frappe/frappe-bench/env/bin/frappe”, line 9, in
load_entry_point(‘frappe==4.7.0’, ‘console_scripts’, ‘frappe’)()
File “/home/frappe/frappe-bench/apps/frappe/frappe/cli.py”, line 40, in main
ret = run(fn, args)
File “/home/frappe/frappe-bench/apps/frappe/frappe/cli.py”, line 84, in run
out = globals().get(fn)(**args)
File “/home/frappe/frappe-bench/apps/frappe/frappe/cli.py”, line 68, in new_fn
return fn(*args, **new_kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/cli.py”, line 432, in latest
frappe.modules.patch_handler.run_all()
File “/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 25, in run_all
if not run_single(patchmodule = patch):
File “/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 50, in run_single
return execute_patch(patchmodule, method, methodargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 66, in execute_patch
frappe.get_attr(patchmodule.split()[0] + “.execute”)()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/patches/v4_2/discount_amount.py”, line 12, in execute
discount_amount=discount_amount/conversion_rate""".format(dt))
File “/home/frappe/frappe-bench/apps/frappe/frappe/database.py”, line 121, in sql
self._cursor.execute(query)
File “/home/frappe/frappe-bench/env/lib/python2.7/site-packages/MySQLdb/cursors.py”, line 205, in execute
self.errorhandler(self, exc, value)
File “/home/frappe/frappe-bench/env/lib/python2.7/site-packages/MySQLdb/connections.py”, line 36, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (1146, “Table ‘site1.local.tabSales invoice’ doesn’t exist”)
Error: None
Traceback (most recent call last):
File “/usr/bin/bench”, line 9, in
load_entry_point(‘bench==0.1’, ‘console_scripts’, ‘bench’)()
File “/home/frappe/bench-repo/bench/cli.py”, line 38, in cli
return bench()
File “/usr/lib/python2.7/site-packages/click/core.py”, line 610, in call
return self.main(*args, **kwargs)
File “/usr/lib/python2.7/site-packages/click/core.py”, line 590, in main
rv = self.invoke(ctx)
File “/usr/lib/python2.7/site-packages/click/core.py”, line 936, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/usr/lib/python2.7/site-packages/click/core.py”, line 782, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/usr/lib/python2.7/site-packages/click/core.py”, line 416, in invoke
return callback(*args, **kwargs)
File “/home/frappe/bench-repo/bench/cli.py”, line 170, in update
patch_sites()
File “/home/frappe/bench-repo/bench/utils.py”, line 91, in patch_sites
exec_cmd("{frappe} --latest all".format(frappe=get_frappe(bench=bench)), cwd=os.path.join(bench, ‘sites’))
File “/home/frappe/bench-repo/bench/utils.py”, line 61, in exec_cmd
subprocess.check_call(cmd, cwd=cwd, shell=True)
File “/usr/lib/python2.7/subprocess.py”, line 540, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command ‘/home/frappe/frappe-bench/env/bin/frappe --latest all’ returned non-zero exit status 1
[root@erpserver frappe-bench]#

This is what is showing after update the bench

There was a bug in the patch. Have released a fix. Please run bench update again.

Thank you dear after bench update ERPNEXT web access is normal now and we can access the Desk.

But my main Problem DOWNLOAD PDF is still there, Now we are getting this error once we click on download PDF, Tell me what we have to do for this error.

Traceback (innermost last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/app.py”, line 52, in application
response = frappe.api.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/api.py”, line 42, in handle
return frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 66, in handle
execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 89, in execute_cmd
ret = frappe.call(method, **frappe.form_dict)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 531, in call
return fn(*args, **newargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/templates/pages/print.py”, line 94, in download_pdf
frappe.local.response.filecontent = get_pdf(html)
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/pdf.py”, line 28, in get_pdf
pdfkit.from_string(html, fname, options=options or {})
File “/home/frappe/frappe-bench/env/lib/python2.7/site-packages/pdfkit/api.py”, line 68, in from_string
return r.to_pdf(output_path)
File “/home/frappe/frappe-bench/env/lib/python2.7/site-packages/pdfkit/pdfkit.py”, line 116, in to_pdf
raise IOError(‘wkhtmltopdf reported an error:\n’ + stderr.decode(‘utf-8’))
IOError: wkhtmltopdf reported an error:
Loading pages (1/6)
[> ] 0%
[======> ] 10%
[==========> ] 17%
Warning: Failed to load file:///tmp/localhost/assets/frappe/css/bootstrap.css (ignore)
Warning: Failed to load file:///tmp/localhost/files/Fast Link (2)400(1).jpg (ignore)
[============================================================] 100%
Counting pages (2/6)
[============================================================] Object 1 of 1
Warning: Received createRequest signal on a disposed ResourceObject’s NetworkAccessManager. This migth be an indication of an iframe taking to long to load.
Warning: Received createRequest signal on a disposed ResourceObject’s NetworkAccessManager. This migth be an indication of an iframe taking to long to load.
Resolving links (4/6)
[============================================================] Object 1 of 1
Loading headers and footers (5/6)
Printing pages (6/6)
[> ] Preparing
[==============================> ] Page 1 of 2
[============================================================] Page 2 of 2
Done
Exit with code 1 due to network error: ContentNotFoundError

Prompt reply we will appreciated.

Did you also run

bench setup nginx # regenerates nginx config
service nginx restart

?

If yes, please give the output of

ls /home/frappe/frappe-bench/sites
cat /home/frappe/frappe-bench/sites/site1.local/site_config.json

You can hide the passwords, I am interested in “host_name” key if it exists.

Yes bench update nginx we did and restart the service aswell,

Below is output for site.config.json file

[root@ERPSERVER /]# cat /home/frappe/frappe-bench/sites/site1.local/site_config.json
{
“db_password”: “password”,
“db_name”: “site1.local”,
“host_name”: “localhost”
}[root@ERPSERVER /]#

I think the hostname is localhost

There is anything els we do to fix the problem ?

The strange thing is it trying to load images from file:///tmp/localhost.

I suggest that you edit the file and remove the host_name line and also remove the comma in the second line and try again.

It should look something like,

{
 "db_password": "password",
 "db_name": "site1.local"
}

Also regenerate and restart nginx after making this change.

bench setup nginx # regenerates nginx config
service nginx restart

Thank you so much Guys, Now its working fine, we are able to Download the PDF file from Download PDF link,

Thank you guys once again for your help.

Regards

Waheed