frappe / erpnext

Free and Open Source Enterprise Resource Planning (ERP)
https://erpnext.com
GNU General Public License v3.0
17.49k stars 6.68k forks source link

error wkhtmltopdf library when converting HTML to PDF (email receipt on POS) #41974

Open Nyuuk opened 1 week ago

Nyuuk commented 1 week ago

Information about bug

Hello,

I encountered an issue when trying to send an email receipt from POS, and I found this error in the Email Queue List.

Thank you.

Module

selling

Version

Installation method

docker

Relevant log output / Stack trace / Full Error Message.

File "/workspace/frappe-dev-toko-ac/apps/frappe/frappe/email/doctype/email_queue/email_queue.py", line 167, in send
    message = ctx.build_message(recipient.recipient)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/frappe-dev-toko-ac/apps/frappe/frappe/email/doctype/email_queue/email_queue.py", line 314, in build_message
    message = self.include_attachments(message)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/frappe-dev-toko-ac/apps/frappe/frappe/email/doctype/email_queue/email_queue.py", line 387, in include_attachments
    print_format_file = frappe.attach_print(**attachment)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/frappe-dev-toko-ac/apps/frappe/frappe/__init__.py", line 2225, in attach_print
    else get_print(doctype, name, **kwargs)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/frappe-dev-toko-ac/apps/frappe/frappe/__init__.py", line 2184, in get_print
    return get_pdf(html, options=pdf_options, output=output) if as_pdf else html
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/frappe-dev-toko-ac/apps/frappe/frappe/utils/pdf.py", line 90, in get_pdf
    filedata = pdfkit.from_string(html, options=options or {}, verbose=True)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/frappe-dev-toko-ac/env/lib/python3.11/site-packages/pdfkit/api.py", line 75, in from_string
    return r.to_pdf(output_path)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/frappe-dev-toko-ac/env/lib/python3.11/site-packages/pdfkit/pdfkit.py", line 201, in to_pdf
    self.handle_error(exit_code, stderr)
  File "/workspace/frappe-dev-toko-ac/env/lib/python3.11/site-packages/pdfkit/pdfkit.py", line 155, in handle_error
    raise IOError('wkhtmltopdf reported an error:\n' + stderr)
Nyuuk commented 1 week ago

here is log from Error Log:

Traceback with variables (most recent call last):
  File "apps/frappe/frappe/email/queue.py", line 150, in flush
    email_queue.send()
      EmailQueue = <class 'frappe.email.doctype.email_queue.email_queue.EmailQueue'>
      email_queue_batch = [{'name': '9kvdu2gk51', 'sender': 'Administrator <admin@example.com>'}]
      failed_email_queues = []
      row = {'name': '9kvdu2gk51', 'sender': 'Administrator <admin@example.com>'}
      email_queue = <EmailQueue: 9kvdu2gk51>
  File "apps/frappe/frappe/email/doctype/email_queue/email_queue.py", line 167, in send
    message = ctx.build_message(recipient.recipient)
      self = <EmailQueue: 9kvdu2gk51>
      smtp_server_instance = None
      ctx = <frappe.email.doctype.email_queue.email_queue.SendMailContext object at 0x7f408c157b90>
      message = None
      recipient = <EmailQueueRecipient: 9kvdmc0c7t parent=9kvdu2gk51>
  File "apps/frappe/frappe/email/doctype/email_queue/email_queue.py", line 314, in build_message
    message = self.include_attachments(message)
      self = <frappe.email.doctype.email_queue.email_queue.SendMailContext object at 0x7f408c157b90>
      recipient_email = 'adnankhafabi@gmail.com'
      message = 'Content-Type: multipart/mixed; boundary="===============5075836870118577313=="\r\nMIME-Version: 1.0\r\nMessage-Id: <171896227500.76.2347418120423753195@dev.toko-ac.com>\r\nX-Original-From: Administrator <admin@example.com>\r\nSubject: POS Invoice: ACC-PSINV-2024-00008\r\nFrom: Administrator <admin@example.com>\r\nTo: adnankhafabi@gmail.com\r\nDate: Fri, 21 Jun 2024 09:31:16 -0000\r\nReply-To: admin@example.com\r\nX-Frappe-Site: http://dev-ac-shop.incenter.id:8003\r\n\r\n--===============5075836870118577313==\r\nContent-Type: multipart/alternative; boundary="===============5377778225347484015=="\r\nMIME-Version: 1.0\r\n\r\n--===============5377778225347484015==\r\nContent-Type: text/plain; charset="utf-8"\r\nMIME-Version: 1.0\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\nPOS Invoice: ACC-PSINV-2024-00008 [View this in your browser](http://dev-ac=\r\n-shop.incenter.id:8003/POS\r\nInvoice/ACC-PSINV-2024-00008?format=3DPOS%20Invoice&key=3D3bc12905cd8bfc846=\r\n7f2d4c55)\r\n\r\n\r\...
  File "apps/frappe/frappe/email/doctype/email_queue/email_queue.py", line 387, in include_attachments
    print_format_file = frappe.attach_print(**attachment)
      self = <frappe.email.doctype.email_queue.email_queue.SendMailContext object at 0x7f408c157b90>
      message = 'Content-Type: multipart/mixed; boundary="===============5075836870118577313=="\r\nMIME-Version: 1.0\r\nMessage-Id: <171896227500.76.2347418120423753195@dev.toko-ac.com>\r\nX-Original-From: Administrator <admin@example.com>\r\nSubject: POS Invoice: ACC-PSINV-2024-00008\r\nFrom: Administrator <admin@example.com>\r\nTo: adnankhafabi@gmail.com\r\nDate: Fri, 21 Jun 2024 09:31:16 -0000\r\nReply-To: admin@example.com\r\nX-Frappe-Site: http://dev-ac-shop.incenter.id:8003\r\n\r\n--===============5075836870118577313==\r\nContent-Type: multipart/alternative; boundary="===============5377778225347484015=="\r\nMIME-Version: 1.0\r\n\r\n--===============5377778225347484015==\r\nContent-Type: text/plain; charset="utf-8"\r\nMIME-Version: 1.0\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\nPOS Invoice: ACC-PSINV-2024-00008 [View this in your browser](http://dev-ac=\r\n-shop.incenter.id:8003/POS\r\nInvoice/ACC-PSINV-2024-00008?format=3DPOS%20Invoice&key=3D3bc12905cd8bfc846=\r\n7f2d4c55)\r\n\r\n\r\...
      message_obj = <email.message.EmailMessage object at 0x7f408964e610>
      attachments = [{'print_format': 'POS Invoice', 'html': None, 'doctype': 'POS Invoice', 'name': 'ACC-PSINV-2024-00008', 'lang': 'en', 'print_letterhead': True}]
      attachment = {'print_format': 'POS Invoice', 'html': None, 'doctype': 'POS Invoice', 'name': 'ACC-PSINV-2024-00008', 'lang': 'en', 'print_letterhead': True}
      file_filters = {}
  File "apps/frappe/frappe/__init__.py", line 2225, in attach_print
    else get_print(doctype, name, **kwargs)
      doctype = 'POS Invoice'
      name = 'ACC-PSINV-2024-00008'
      file_name = None
      print_format = 'POS Invoice'
      style = None
      html = None
      doc = None
      lang = 'en'
      print_letterhead = True
      password = ********
      letterhead = None
      print_language = <function print_language at 0x7f408a0b6700>
      scrub_urls = <function scrub_urls at 0x7f408d8d0e00>
      get_pdf = <function get_pdf at 0x7f40896d3060>
      print_settings = {'add_draft_heading': '1', 'allow_page_break_inside_tables': '0', 'allow_print_for_cancelled': '0', 'allow_print_for_draft': '1', 'creation': None, 'docstatus': '0', 'enable_print_server': '0', 'enable_raw_printing': '0', 'font': 'Default', 'font_size': '0', 'idx': '0', 'modified': '2024-06-12 07:43:09.846416', 'modified_by': 'Administrator', 'name': 'Print Settings', 'owner': 'Administrator', 'pdf_page_height': '0', 'pdf_page_size': 'A4', 'pdf_page_width': '0', 'print_style': 'Redesign', 'repeat_header_footer': '1', 'send_print_as_pdf': '1', 'with_letterhead': '1'}
      kwargs = {'print_format': 'POS Invoice', 'style': None, 'doc': None, 'no_letterhead': False, 'letterhead': None, 'password': '********', 'as_pdf': True}
      content = ''
      ext = '.pdf'
  File "apps/frappe/frappe/__init__.py", line 2184, in get_print
    return get_pdf(html, options=pdf_options, output=output) if as_pdf else html
      doctype = 'POS Invoice'
      name = 'ACC-PSINV-2024-00008'
      print_format = 'POS Invoice'
      style = None
      as_pdf = True
      doc = None
      output = None
      no_letterhead = False
      password = ********
      pdf_options = {}
      letterhead = None
      get_pdf = <function get_pdf at 0x7f40896d3060>
      get_response_without_exception_handling = <function get_response_without_exception_handling at 0x7f408964a3e0>
      original_form_dict = {}
      response = <Response 7303 bytes [200 OK]>
      html = '<!DOCTYPE html>\n<html lang="en" dir="ltr">\n<head>\n\t<meta charset="utf-8">\n\t<meta name="viewport" content="width=device-width, initial-scale=1.0">\n\t<title>Adnan</title>\n\t<meta name="generator" content="frappe">\n\t<link type="text/css" rel="stylesheet" href="/assets/frappe/dist/css/print.bundle.B6AKYMV4.css">\n\t\n\t\t<style>\n\t\t@media screen {\n\t.print-format-gutter {\n\t\tbackground-color: #d1d8dd;\n\t\tpadding: 30px 0px;\n\t}\n\t.print-format {\n\t\tbackground-color: white;\n\t\tborder-radius: 8px;\n\t\tmax-width: 8.3in;\n\t\tmin-height: 11.69in;\n\t\tpadding: 0.75in;\n\t\tmargin: auto;\n\t\tcolor: var(--gray-900);\n\t}\n\n\t.print-format.landscape {\n\t\tmax-width: 11.69in;\n\t\tpadding: 0.2in;\n\t}\n\n\t.page-break {\n\t\t/* padding: 15px 0px; */\n\t\tborder-bottom: 1px dashed #888;\n\t}\n\n\t/* .page-break:first-child {\n\t\tpadding-top: 0px;\n\t} */\n\n\t.page-break:last-child {\n\t\tborder-bottom: 0px;\n\t}\n\n\t/* mozilla hack for images in table */\n\tbody:last-c...
  File "apps/frappe/frappe/utils/pdf.py", line 90, in get_pdf
    filedata = pdfkit.from_string(html, options=options or {}, verbose=True)
      html = '<!DOCTYPE html>\n\n<html dir="ltr" lang="en"><head>\n<meta charset="utf-8"/>\n<meta content="width=device-width, initial-scale=1.0" name="viewport"/>\n<title>Adnan</title>\n<meta content="frappe" name="generator"/>\n<link href="http://dev.toko-ac.com:8003/assets/frappe/dist/css/print.bundle.B6AKYMV4.css" rel="stylesheet" type="text/css"/>\n<style>\n\t\t@media screen {\n\t.print-format-gutter {\n\t\tbackground-color: #d1d8dd;\n\t\tpadding: 30px 0px;\n\t}\n\t.print-format {\n\t\tbackground-color: white;\n\t\tborder-radius: 8px;\n\t\tmax-width: 8.3in;\n\t\tmin-height: 11.69in;\n\t\tpadding: 0.75in;\n\t\tmargin: auto;\n\t\tcolor: var(--gray-900);\n\t}\n\n\t.print-format.landscape {\n\t\tmax-width: 11.69in;\n\t\tpadding: 0.2in;\n\t}\n\n\t.page-break {\n\t\t/* padding: 15px 0px; */\n\t\tborder-bottom: 1px dashed #888;\n\t}\n\n\t/* .page-break:first-child {\n\t\tpadding-top: 0px;\n\t} */\n\n\t.page-break:last-child {\n\t\tborder-bottom: 0px;\n\t}\n\n\t/* mozilla hack for images in table */\n...
      options = {'print-media-type': None, 'background': None, 'images': None, 'quiet': None, 'encoding': 'UTF-8', 'margin-right': '15mm', 'margin-left': '15mm', 'margin-top': '15mm', 'margin-bottom': '15mm', 'page-size': 'A4', 'disable-javascript': '', 'disable-local-file-access': '', 'disable-smart-shrinking': ''}
      output = None
      filedata = ''
  File "env/lib/python3.11/site-packages/pdfkit/api.py", line 75, in from_string
    return r.to_pdf(output_path)
      input = '<!DOCTYPE html>\n\n<html dir="ltr" lang="en"><head>\n<meta charset="utf-8"/>\n<meta content="width=device-width, initial-scale=1.0" name="viewport"/>\n<title>Adnan</title>\n<meta content="frappe" name="generator"/>\n<link href="http://dev.toko-ac.com:8003/assets/frappe/dist/css/print.bundle.B6AKYMV4.css" rel="stylesheet" type="text/css"/>\n<style>\n\t\t@media screen {\n\t.print-format-gutter {\n\t\tbackground-color: #d1d8dd;\n\t\tpadding: 30px 0px;\n\t}\n\t.print-format {\n\t\tbackground-color: white;\n\t\tborder-radius: 8px;\n\t\tmax-width: 8.3in;\n\t\tmin-height: 11.69in;\n\t\tpadding: 0.75in;\n\t\tmargin: auto;\n\t\tcolor: var(--gray-900);\n\t}\n\n\t.print-format.landscape {\n\t\tmax-width: 11.69in;\n\t\tpadding: 0.2in;\n\t}\n\n\t.page-break {\n\t\t/* padding: 15px 0px; */\n\t\tborder-bottom: 1px dashed #888;\n\t}\n\n\t/* .page-break:first-child {\n\t\tpadding-top: 0px;\n\t} */\n\n\t.page-break:last-child {\n\t\tborder-bottom: 0px;\n\t}\n\n\t/* mozilla hack for images in table */\n...
      output_path = None
      options = {'print-media-type': None, 'background': None, 'images': None, 'quiet': None, 'encoding': 'UTF-8', 'margin-right': '15mm', 'margin-left': '15mm', 'margin-top': '15mm', 'margin-bottom': '15mm', 'page-size': 'A4', 'disable-javascript': '', 'disable-local-file-access': '', 'disable-smart-shrinking': ''}
      toc = None
      cover = None
      css = None
      configuration = None
      cover_first = False
      verbose = True
      r = <pdfkit.pdfkit.PDFKit object at 0x7f4088c31d10>
  File "env/lib/python3.11/site-packages/pdfkit/pdfkit.py", line 201, in to_pdf
    self.handle_error(exit_code, stderr)
      self = <pdfkit.pdfkit.PDFKit object at 0x7f4088c31d10>
      path = None
      args = ['/usr/local/bin/wkhtmltopdf', '--print-media-type', '--background', '--images', '--quiet', '--encoding', 'UTF-8', '--margin-right', '15mm', '--margin-left', '15mm', '--margin-top', '15mm', '--margin-bottom', '15mm', '--page-size', 'A4', '--disable-javascript', '--disable-local-file-access', '--disable-smart-shrinking', '-', '-']
      result = <Popen: returncode: 1 args: ['/usr/local/bin/wkhtmltopdf', '--print-media-ty...>
      input = b'<!DOCTYPE html>\n\n<html dir="ltr" lang="en"><head>\n<meta charset="utf-8"/>\n<meta content="width=device-width, initial-scale=1.0" name="viewport"/>\n<title>Adnan</title>\n<meta content="frappe" name="generator"/>\n<link href="http://dev.toko-ac.com:8003/assets/frappe/dist/css/print.bundle.B6AKYMV4.css" rel="stylesheet" type="text/css"/>\n<style>\n\t\t@media screen {\n\t.print-format-gutter {\n\t\tbackground-color: #d1d8dd;\n\t\tpadding: 30px 0px;\n\t}\n\t.print-format {\n\t\tbackground-color: white;\n\t\tborder-radius: 8px;\n\t\tmax-width: 8.3in;\n\t\tmin-height: 11.69in;\n\t\tpadding: 0.75in;\n\t\tmargin: auto;\n\t\tcolor: var(--gray-900);\n\t}\n\n\t.print-format.landscape {\n\t\tmax-width: 11.69in;\n\t\tpadding: 0.2in;\n\t}\n\n\t.page-break {\n\t\t/* padding: 15px 0px; */\n\t\tborder-bottom: 1px dashed #888;\n\t}\n\n\t/* .page-break:first-child {\n\t\tpadding-top: 0px;\n\t} */\n\n\t.page-break:last-child {\n\t\tborder-bottom: 0px;\n\t}\n\n\t/* mozilla hack for images in table */\...
      stdout = b'%PDF-1.4\n1 0 obj\n<<\n/Title (\xfe\xff\x00A\x00d\x00n\x00a\x00n)\n/Creator (\xfe\xff\x00w\x00k\x00h\x00t\x00m\x00l\x00t\x00o\x00p\x00d\x00f\x00 \x000\x00.\x001\x002\x00.\x006\x00.\x001)\n/Producer (\xfe\xff\x00Q\x00t\x00 \x004\x00.\x008\x00.\x007)\n/CreationDate (D:20240621164409+07\'00\')\n>>\nendobj\n3 0 obj\n<<\n/Type /ExtGState\n/SA true\n/SM 0.02\n/ca 1.0\n/CA 1.0\n/AIS false\n/SMask /None>>\nendobj\n4 0 obj\n[/Pattern /DeviceRGB]\nendobj\n8 0 obj\n<<\n/Type /Annot\n/Subtype /Link\n/Rect [80.2500000  785  129  799.250000 ]\n/Border [0 0 0]\n/A <<\n/Type /Action\n/S /URI\n/URI (http://dev.toko-ac.com:8003/api/method/frappe.utils.print_format.download_pdf?doctype=POS%20Invoice&name=ACC-PSINV-2024-00008&key=None)\n>>\n>>\nendobj\n9 0 obj\n<<\n/Type /Catalog\n/Pages 2 0 R\n>>\nendobj\n5 0 obj\n<<\n/Type /Page\n/Parent 2 0 R\n/Contents 10 0 R\n/Resources 12 0 R\n/Annots 13 0 R\n/MediaBox [0 0 595 842]\n>>\nendobj\n12 0 obj\n<<\n/ColorSpace <<\n/PCSp 4 0 R\n/CSp /DeviceRGB\n/CSpg /De...
      stderr = 'Exit with code 1 due to network error: HostNotFoundError\n'
      exit_code = 1
  File "env/lib/python3.11/site-packages/pdfkit/pdfkit.py", line 155, in handle_error
    raise IOError('wkhtmltopdf reported an error:\n' + stderr)
      exit_code = 1
      stderr = 'Exit with code 1 due to network error: HostNotFoundError\n'
      stderr_lines = ['Exit with code 1 due to network error: HostNotFoundError']
builtins.OSError: wkhtmltopdf reported an error:
Exit with code 1 due to network error: HostNotFoundError
Nyuuk commented 1 week ago

where i can edit this host

Reply-To: admin@example.com\r\nX-Frappe-Site: http://dev-ac-shop.incenter.id:8003\r\n\r\n

i want to remove port :8003