Html to pdf api error

Below error coming when trying to generate pdf. This is also causing issue in the email. Help please

Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 67, in application
response = frappe.api.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 53, in handle
return frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 22, in handle
data = execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 53, in execute_cmd
return, **frappe.form_dict)
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 939, in call
return fn(*args, **newargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/”, line 48, in download_pdf
frappe.local.response.filecontent = get_pdf(html)
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/”, line 17, in get_pdf
pdfkit.from_string(html, fname, options=options or {})
File “/home/frappe/frappe-bench/env/src/pdfkit/pdfkit/”, line 68, in from_string
return r.to_pdf(output_path)
File “/home/frappe/frappe-bench/env/src/pdfkit/pdfkit/”, line 140, in to_pdf
raise IOError(‘wkhtmltopdf reported an error:\n’ + stderr.decode(‘utf-8’))
IOError: wkhtmltopdf reported an error:
Error: Authentication Required
Error: Authentication Required
Error: Authentication Required
Error: Authentication Required
Error: Authentication Required
Error: Authentication Required

Can you check if your user has permissions for the /tmp folder? This is a similar error as asked in this post

Dear Raghu,

Thank you for your kind reply. I checked the /tmp folder and reset the permissions. still the error is same. cannot send email with pdf attachment.

Hi @shelteradmin,

can you try to troubleshoot what is happening in wkhtmltopdf? For this, e.g. temporarily insert frappe.throw(html) in frappe/utils/ (after line 12) and then copy the html code into a file (file.html), copy it to the server and on the server run

$ wkhtmltopdf file.html file.pdf

Observe the exact error. You can also look into the html and search for resources that might not be accessible from the server…

Hi @lasalesi,

Thank you for the update. I tried the same above and it worked without any error. the pdf file is generated in a few seconds. There is issue with the ubuntu authentication maybe. All files in the frappe-bench are under user frappe.


Hi @shelteradmin,

if the above works, then it is most probably your /tmp folder access, where Frappe will temporarily store the pdf output. Try the above with the output file as /tmp/file.pdf and you should find the same error. Your /tmp should be drwxrwxrwt owned by root:root

By the way, the same topic is in Server error on trying to generate pdf, let use know once it is fixed :wink:

Hey @lasalesi,

Thanks a lot for the help. I gave the proper rights as your suggestions but the issue is the same. There is a confusion for this right now. Please see the following, on the server end everything is ok. But the error is same on the client end, cannot send email due to this error.

frappe@haqbani:~/frappe-bench/apps/frappe/frappe/utils$ ls -ld /tmp
drwxrwxrwt 4 root root 4096 Feb 5 13:14 /tmp
frappe@haqbani:~/frappe-bench/apps/frappe/frappe/utils$ wkhtmltopdf pdf.html /tmp/file.pdf
Loading pages (1/6)
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)

Hi @shelteradmin,

does the issue correlate with the user who is generating the pdf? Can you generate the pdf as System Manager?

Are there steps to reproduce this issue? Did it work in the beginning? Which version of wkhtmltopdf are you using (wkhtmltopdf -V)? I would be curious to reproduce this, especially as this seems to affect other people as well…

Hey @lasalesi,

I tried with Administrator account and the system manager, both have the same issue, so correlation with user seems not an issue. The version is this one :

frappe@haqbani:~/frappe-bench$ wkhtmltopdf -V
wkhtmltopdf 0.12.3 (with patched qt)

It was working perfectly a week ago. Please help.

Hi @shelteradmin,

do you remember configuration changes or similar since it was working well?

Hey @lasalesi,

I did the git reset for frappe also, but the issue is same. I didn’t make any configuration changes for the pdfkit or files related to that at all.

Other than mailing does other pdf generation work in invoicing etc?

The “authorization error” here is it connecting to the http server to load the page, it’s not /tmp permissions. Is basic authentication enforced on the server?

Pdf generation doesn’t work at all. When i click pdf the above error comes

The server configuration is default as before. I didn’t change the protocols.

Thank you everyone. The issue is solved. It was basically the right issue for the env folder and then after the system scheduler running everything is back to normal. Also add the following line to site_config json :

“host_name” : “http://localhost”,