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.
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
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.
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
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.