Server error on trying to generate pdf

Hi,
I am getting the following error every time I try to generate a PDF. I am not sure how to mitigate the problem.
Please help:

Traceback (innermost last):
File “/home/nitin/frappe-bench/apps/frappe/frappe/app.py”, line 60, in application
response = frappe.api.handle()
File “/home/nitin/frappe-bench/apps/frappe/frappe/api.py”, line 50, in handle
return frappe.handler.handle()
File “/home/nitin/frappe-bench/apps/frappe/frappe/handler.py”, line 19, in handle
execute_cmd(cmd)
File “/home/nitin/frappe-bench/apps/frappe/frappe/handler.py”, line 36, in execute_cmd
ret = frappe.call(method, **frappe.form_dict)
File “/home/nitin/frappe-bench/apps/frappe/frappe/init.py”, line 806, in call
return fn(*args, **newargs)
File “/home/nitin/frappe-bench/apps/frappe/frappe/templates/pages/print.py”, line 182, in download_pdf
frappe.local.response.filecontent = get_pdf(html)
File “/home/nitin/frappe-bench/apps/frappe/frappe/utils/pdf.py”, line 16, in get_pdf
pdfkit.from_string(html, fname, options=options or {})
File “/home/nitin/frappe-bench/env/src/pdfkit/pdfkit/api.py”, line 68, in from_string
return r.to_pdf(output_path)
File “/home/nitin/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:
Error: Authentication Required
Error: Authentication Required

I notice that this problem doesn’t occur when I try to generate pdf on the server itself.

Thanks
Nitin

Please Help me with this.

Hi @NitinAgarwal,

Seems there is an issue with the /tmp folder permission. Can you check whether you are able to access the /tmp folder.

HI @rohit_w,

Where can i find this /tmp folder?

I can’t send out emails with purchase orders due to this error it seems.

thx, Sebastian

same issue

Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/app.py”, line 60, in application
response = frappe.api.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/api.py”, line 54, in handle
return frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 21, in handle
data = execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 52, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 907, in call
return fn(*args, **newargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/print_format.py”, line 48, in download_pdf
frappe.local.response.filecontent = get_pdf(html)
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:
Error: Authentication Required
Error: Authentication Required
Error: Authentication Required
Error: Authentication Required

Late reply, but I am leaving the solution I used to solve this problem in case it helps someone else out.

  1. My problem arose when I put Password Authentication (digest auth) in Nginx.
  2. The way I setup the Password Authentication was by following instructions on https://www.digitalocean.com/community/tutorials/how-to-set-up-password-authentication-with-nginx-on-ubuntu-14-04

a. Open /home/frappe/frappe-bench/config/nginx.conf
b.
Locate the following:
location / {
try_files /$site_name_sqcmbbw/public/$uri @webserver;
}
If you have SSL enabled, then you will have to do the following twice, because there will be 2 of these: location /{…
c. Make changes so it looks like:
location / {
try_files /$site_name_sqcmbbw/public/$uri @webserver;
auth_basic “Restricted Content”;
auth_basic_user_file /etc/nginx/.htpasswd;
}

Note that /etc/nginx/.htpasswd contains your Password Auth credentials.

  1. PROBLEM: I got the same error codes as above. 4 times Authentication Required:
    IOError: wkhtmltopdf reported an error:
    Error: Authentication Required
    Error: Authentication Required
    Error: Authentication Required
    Error: Authentication Required

  2. SOLUTION:
    You have to bypass Password Authentication for 2 IP addresses:
    Localhost IP: 127.0.0.1
    Your server’s public IP address whatever it maybe
    So, you have to edit the /home/frappe/frappe-bench/config/nginx.conf file again as follows:
    a. Locate location / {
    b. And make the following changes
    location / {
    try_files /$site_name_sqcmbbw/public/$uri @webserver;
    satisfy any;
    allow 127.0.0.1;
    allow 54.45.253.1; #CHANGE THIS TO YOUR SERVER PUBLIC IP ADDRESS
    auth_basic “Restricted Content”;
    auth_basic_user_file /etc/nginx/.htpasswd;
    }

This resolved the problem for me. Let me know if it helps you out as well.