Unable to send Payment request (internal server error)

When I try to send a request payment I get an error 500

bench version
erpnext 11.1.8
frappe 11.1.7
bench --version
4.1.0
wkhtmltopdf --version
wkhtmltopdf 0.12.4 (with patched qt)

Any idea on how to solve this?

jquery.min.js:4 POST http://erp.example.pro/ 500 (Internal Server Error)
send @ jquery.min.js:4
ajax @ jquery.min.js:4
frappe.request.call @ request.js:199
frappe.call @ request.js:77
(anonymous) @ VM1259:26
i @ page.js:371
dispatch @ jquery.min.js:3
r.handle @ jquery.min.js:3
request.js:253 Unable to handle failed response
request.js:254 SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at Object.frappe.request.report_error (request.js:374)
    at 500 (request.js:172)
    at Object.<anonymous> (request.js:247)
    at i (jquery.min.js:2)
    at Object.fireWith [as rejectWith] (jquery.min.js:2)
    at z (jquery.min.js:4)
    at XMLHttpRequest.<anonymous> (jquery.min.js:4)

I reinstall wkhtmltopdf and now i get

Traceback (most recent call last):
  File "/home/magana/frappe-bench/apps/frappe/frappe/app.py", line 61, in application
    response = frappe.handler.handle()
  File "/home/magana/frappe-bench/apps/frappe/frappe/handler.py", line 21, in handle
    data = execute_cmd(cmd)
  File "/home/magana/frappe-bench/apps/frappe/frappe/handler.py", line 56, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/magana/frappe-bench/apps/frappe/frappe/__init__.py", line 1026, in call
    return fn(*args, **newargs)
  File "/home/magana/frappe-bench/apps/erpnext/erpnext/accounts/doctype/payment_request/payment_request.py", line 381, in resend_payment_email
    return frappe.get_doc("Payment Request", docname).send_email()
  File "/home/magana/frappe-bench/apps/erpnext/erpnext/accounts/doctype/payment_request/payment_request.py", line 195, in send_email
    file_name=self.reference_name, print_format=self.print_format)]}
  File "/home/magana/frappe-bench/apps/frappe/frappe/__init__.py", line 1376, in attach_print
    "fcontent": get_print(doctype, name, print_format=print_format, style=style, html=html, as_pdf=True, doc=doc, no_letterhead=no_letterhead)
  File "/home/magana/frappe-bench/apps/frappe/frappe/__init__.py", line 1353, in get_print
    return get_pdf(html, output = output)
  File "/home/magana/frappe-bench/apps/frappe/frappe/utils/pdf.py", line 23, in get_pdf
    pdfkit.from_string(html, fname, options=options or {})
  File "/home/magana/frappe-bench/env/src/pdfkit/pdfkit/api.py", line 68, in from_string
    return r.to_pdf(output_path)
  File "/home/magana/frappe-bench/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")))
IOError: wkhtmltopdf exited with non-zero code -6. error:
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 --print-media-type, is not support using unpatched qt, and will be ignored.QXcbConnection: Could not connect to display

And frappe-bench/logs/web.error.log has the following

UnicodeDecodeError: 'utf8' codec can't decode byte 0xfe in position 28: invalid start byte
[2019-02-20 14:07:10 +0000] [14153] [ERROR] Error handling request /
Traceback (most recent call last):
  File "/home/magana/frappe-bench/env/local/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 135, in handle
    self.handle_request(listener, req, client, addr)
  File "/home/magana/frappe-bench/env/local/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 176, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/home/magana/frappe-bench/env/local/lib/python2.7/site-packages/werkzeug/local.py", line 228, in application
    return ClosingIterator(app(environ, start_response), self.cleanup)
  File "/home/magana/frappe-bench/env/local/lib/python2.7/site-packages/werkzeug/wrappers.py", line 308, in application
    resp = f(*args[:-2] + (request,))
  File "/home/magana/frappe-bench/apps/frappe/frappe/app.py", line 87, in application
    response = handle_exception(e)
  File "/home/magana/frappe-bench/apps/frappe/frappe/app.py", line 148, in handle_exception
    response = frappe.utils.response.report_error(http_status_code)
  File "/home/magana/frappe-bench/apps/frappe/frappe/utils/response.py", line 30, in report_error
    frappe.errprint(frappe.utils.get_traceback())
  File "/home/magana/frappe-bench/apps/frappe/frappe/__init__.py", line 278, in errprint
    error_log.append({"exc": escape_html(msg), "locals": get_frame_locals()})
  File "/home/magana/frappe-bench/apps/frappe/frappe/utils/error.py", line 210, in get_frame_locals
    _locals.append('File "{}", line {}, in {}\n{}'.format(filename, lineno, function, json.dumps(frame.f_locals, default=str, indent=4)))
  File "/usr/lib/python2.7/json/__init__.py", line 251, in dumps
    sort_keys=sort_keys, **kw).encode(obj)
 File "/usr/lib/python2.7/json/encoder.py", line 209, in encode
    chunks = list(chunks)
  File "/usr/lib/python2.7/json/encoder.py", line 434, in _iterencode
    for chunk in _iterencode_dict(o, _current_indent_level):
  File "/usr/lib/python2.7/json/encoder.py", line 408, in _iterencode_dict
    for chunk in chunks:
  File "/usr/lib/python2.7/json/encoder.py", line 408, in _iterencode_dict
    for chunk in chunks:
  File "/usr/lib/python2.7/json/encoder.py", line 332, in _iterencode_list
    for chunk in chunks:
  File "/usr/lib/python2.7/json/encoder.py", line 390, in _iterencode_dict
    yield _encoder(value)
  File "/usr/lib/python2.7/json/encoder.py", line 434, in _iterencode
    for chunk in _iterencode_dict(o, _current_indent_level):
  File "/usr/lib/python2.7/json/encoder.py", line 408, in _iterencode_dict
    for chunk in chunks:
  File "/usr/lib/python2.7/json/encoder.py", line 408, in _iterencode_dict
    for chunk in chunks:
  File "/usr/lib/python2.7/json/encoder.py", line 332, in _iterencode_list
    for chunk in chunks:
  File "/usr/lib/python2.7/json/encoder.py", line 390, in _iterencode_dict
    yield _encoder(value)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xfe in position 28: invalid start byte

Iā€™m running debian 9 and the erp is in french

Yes probably language or character set related, switching to Python 3 may resolve that.

Well it seems that now i broke all the applicationā€¦
Doing:

$ sudo apt-get install python3-dev
$ bench migrate-env python3

Now i get error 500 on all the pages :cry:

Although not specifically related to error 500, you also have wkhtmltox_0.12.4xx which might be missing a qt dependency. The error log indicates IOError: wkhtmltopdf exited with non-zero code -6. error: so maybeā€¦update to latest version like soā€¦

sudo apt install xfonts-75dpi -y
wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.stretch_amd64.deb
sudo dpkg --install wkhtmltox_0.12.5-1.stretch_amd64.deb

Not sure if itā€™ll help, but maybe

Thanks I manage to fix the error 500 reverting to python 2.7
now wkhtmltopdf is version 0.12.5ā€¦ but i still get the same error

UnicodeDecodeError: ā€˜utf8ā€™ codec canā€™t decode byte 0xfe in position 28: invalid start byte

Though I donā€™t know why (or how to do it), apparently if you change from ā€œUTF8ā€ to ā€œISO-8859-1ā€ it(python) behaves better

1 Like

Hi, I have the same error, could you solve it? Thank you.

ā€˜UnicodeDecodeError: ā€˜utf8ā€™ codec can not decode byteā€™

You need to install the latest stable version 0.12.5 of wkhtmltopdf, as mentioned in the instructions. :wink: